Skip to content
Snippets Groups Projects
Commit 1afd7fc2 authored by Ahmad Alyasaki's avatar Ahmad Alyasaki
Browse files

Issue #3443545: Add support to suggstion for custome classes and supprt slack

parent 70157fc1
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ var gulp = require("gulp"),
gulp.task("sass", function () {
gulp
.src(["./assets/scss/seeds-page.scss"])
.src(["./assets/scss/seeds-page.scss", "./assets/scss/backend.scss"])
.pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer("last 2 version"))
......@@ -21,7 +21,10 @@ gulp.task("build", function () {
gulp.task("watch", ["sass"], function () {
livereload.listen();
gulp.watch("./assets/scss/**/*.scss", ["sass"]);
gulp.watch(["./assets/css/seeds-page.css"], function (files) {
livereload.changed(files);
});
gulp.watch(
["./assets/css/seeds-page.css", "./assets/css/backend.css"],
function (files) {
livereload.changed(files);
}
);
});
......@@ -5,21 +5,11 @@
* Contains seeds_page.module.
*/
/**
* Implements hook_help().
*/
function seeds_page_help($route_name) {
switch ($route_name) {
// Main module help for the seeds_page module.
case 'help.page.seeds_page':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Provides functionalities to customize the experience in pages using paragraphs') . '</p>';
return $output;
default:
return '';
}
}
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\node\Entity\Node;
/**
* Implements hook_theme().
......@@ -36,9 +26,51 @@ function seeds_page_theme($existing, $type, $theme, $path) {
'show_title' => NULL,
],
];
$templates['seeds_slick_wrapper'] = [
'render element' => 'element',
'variables' => [
'contianer' => NULL,
],
'base hook' => 'slick_wrapper',
];
return $templates;
}
/**
* Implements hook_help().
*/
function seeds_page_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the seeds_page module.
case 'help.page.seeds_page':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Provides functionalities to customize the experience in pages using paragraphs') . '</p>';
return $output;
default:
return '';
}
}
/**
*
*/
function seeds_page_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
/** @var \Drupal\seeds_page\SeedsPageManager $seeds_page_manager */
$seeds_page_manager = \Drupal::service('seeds_page.manager');
$entity = $variables['element']['#object'] ?? NULL;
if (isset($variables['element']['#field_type']) && $variables['element']['#field_type'] === 'entity_reference_revisions') {
if ($seeds_page_manager::isSeedsBlock($entity, 'seeds_tabs')) {
$suggestions[] = 'seeds_page_field_paragraph__tabs';
}
}
// Override slick wrapper on block type slider to add a container.
if ($hook === "slick_wrapper" && $seeds_page_manager::isSeedsBlock($entity) && $entity->get('field_seeds_container')->value) {
$suggestions[] = "seeds_slick_wrapper";
}
}
/**
* Implements hook_preprocess_HOOK().
*/
......@@ -93,3 +125,174 @@ function seeds_page_preprocess_page(&$variables) {
}
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function seeds_page_preprocess_block(&$variables) {
$block = $variables["content"]["#block_content"] ?? NULL;
/** @var \Drupal\seeds_page\SeedsPageManager $seeds_page_manager */
$seeds_page_manager = \Drupal::service('seeds_page.manager');
if ($seeds_page_manager::isSeedsBlock($block)) {
// Add library on these block types.
$variables['#attached']['library'][] = 'seeds_page/paragraph_block';
// Add tabs library only on tabs block type.
if ($seeds_page_manager::isSeedsBlock($block, 'seeds_tabs')) {
$variables['#attached']['library'][] = 'seeds_page/tabs';
}
if ($seeds_page_manager::isSeedsBlock($block, "seeds_modal")) {
if ($block->get('field_seeds_container')->value) {
$variables['attributes']['class'][] = "container";
}
}
// Add a unique class.
$variables['attributes']['class'][] = 'seeds-paragraph-block';
// Add parallax class.
if ($block->hasField('field_seeds_block_parallax') && $block->get('field_seeds_block_parallax')->value) {
$variables["attributes"]['class'][] = 'seeds-block-parallax';
}
// Add background class.
if ($block->hasField('field_seeds_background_color') && $block->get('field_seeds_background_color')->value !== '') {
$variables["attributes"]['class'][] = $block->get('field_seeds_background_color')->value;
}
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function seeds_page_preprocess_field(&$variables) {
$entity = $variables["element"]["#object"];
/** @var \Drupal\seeds_page\SeedsPageManager $seeds_page_manager */
$seeds_page_manager = \Drupal::service('seeds_page.manager');
switch ($variables["element"]["#field_name"]) {
case 'field_seeds_text':
if ($seeds_page_manager::isSeedsBlock($entity, 'seeds_modal')) {
$variables["attributes"]['class'][] = 'btn btn-primary';
}
break;
case 'field_seeds_paragraph':
case 'field_seeds_single_paragraph':
if ($seeds_page_manager::isSeedsBlock($entity, 'seeds_grid')) {
$desktop = $entity->field_seeds_desktop->value;
$tablet = $entity->field_seeds_tablet->value;
$mobile = $entity->field_seeds_mobile->value;
foreach ($variables['items'] as &$item) {
$item['attributes']->addClass("$desktop $tablet $mobile");
}
}
if ($seeds_page_manager::isSeedsBlock($entity)) {
$variables['attributes']['class'][] = $entity->get('field_seeds_container')->value ? 'container' : "";
}
break;
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function seeds_page_preprocess_ds_1col(&$variables) {
/** @var \Drupal\seeds_page\SeedsPageManager $seeds_page_manager */
$seeds_page_manager = \Drupal::service('seeds_page.manager');
$paragraph = $variables["content"]["#paragraph"] ?? NULL;
if ($seeds_page_manager::isSeedsParagraph($paragraph)) {
// Add a general class for all paragraph styles.
$variables["attributes"]['class'][] = "seeds-block-paragraph-item";
// Add 'no-image' class if image is not set.
if ($paragraph->field_seeds_image->isEmpty()) {
// Add a custom class.
$variables["attributes"]['class'][] = 'no-image';
}
if ($variables["content"]["#view_mode"] === 'accordion') {
$variables["#attached"]["library"][] = 'seeds_page/accordion';
}
}
}
/**
*
*/
function seeds_page_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
if (preg_match('/block_content_[\w_]+_form/', $form_id)) {
$form['#attached']['library'][] = 'seeds_page/backend';
$form["info"]["widget"][0]["value"]["#title"] = t('Admin Title');
}
}
/**
*
*/
function seeds_page_preprocess_seeds_page_field_paragraph__tabs(&$variables) {
$tabs = [];
$paragraphs = $variables["items"] ?? [];
foreach ($paragraphs as $paragraph) {
$tabs[] = $paragraph["content"]["#paragraph"]->field_seeds_title->value;
}
$variables['tabs'] = $tabs;
}
/**
*
*/
function seeds_page_preprocess_seeds_slick_wrapper(&$variables) {
$variables['container'] = 'container';
}
/**
* Implementation of hook_token_info().
*/
function seeds_page_token_info() {
$tokens['tokens']['site']['node'] = [
'name' => 'Node By ID',
'description' => 'Gets a node with the ID',
'dynamic' => TRUE,
'type' => 'node',
];
return $tokens;
}
/**
*
*/
function seeds_page_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$replacements = [];
if ('site' == $type && ($node_tokens = \Drupal::token()->findWithPrefix($tokens, 'node'))) {
foreach ($node_tokens as $key => $node_token) {
$explode = explode(':', $key);
$nid = $explode[0];
$node = Node::load($nid);
$node_token = [$explode[1] => $node_token];
if ($node) {
$bubbleable_metadata->addCacheableDependency($node);
$replacements += \Drupal::token()->generate('node', $node_token, ['node' => $node], $options, $bubbleable_metadata);
}
}
}
return $replacements;
}
/**
*
*/
function seeds_page_field_widget_entity_reference_paragraphs_form_alter(&$element, &$form_state, $context) {
if (isset($element["subform"]["field_seeds_view_mode"])) {
$options = \Drupal::service('seeds_page.manager')->getAllowedViewModesOptions($element["#paragraph_type"]);
$element["subform"]["field_seeds_view_mode"]["widget"]["#options"] = $options ?? [];
}
}
/**
* Implements hook_entity_view_mode_alter().
*/
function seeds_page_entity_view_mode_alter(&$view_mode, EntityInterface $entity) {
if ($entity->getEntityTypeId() === 'paragraph' && $entity->hasField('field_seeds_view_mode')) {
$view_mode_id = $entity->get('field_seeds_view_mode')->target_id ?? "default";
$view_mode = str_replace("paragraph.", "", $view_mode_id);
}
}
<div {{attributes.addClass(classes, 'tabs')}}>
<ul class = 'tabs-wrapper'>
{% for tab in tabs %}
<li>{{ tab }}</li>
{% endfor %}
</ul>
{% for item in items %}
<div class = 'field--item'>{{ item.content }}</div>
{% endfor %}
</div>
\ No newline at end of file
{#
/**
* @file
* Default theme implementation for a slick wrapper.
*
* Available variables:
* - items: A list of items containing main and thumbnail of slick.html.twig
* which can be re-position using option Thumbnail position.
* - attributes: HTML attributes to be applied to the list.
* - settings: An array containing the given settings.
*
* @ingroup themeable
*/
#}
{%
set classes = [
'slick-wrapper',
settings.nav ? 'slick-wrapper--asnavfor',
settings.skin ? 'slick-wrapper--' ~ settings.skin|clean_class,
settings.skin_thumbnail ? 'slick-wrapper--' ~ settings.skin_thumbnail|clean_class,
settings.vertical ? 'slick-wrapper--v',
settings.vertical_tn ? 'slick-wrapper--v-tn',
settings.thumbnail_position ? 'slick-wrapper--tn-' ~ settings.thumbnail_position|clean_class,
'over' in settings.thumbnail_position ? 'slick-wrapper--tn-overlay',
'over' in settings.thumbnail_position ? 'slick-wrapper--tn-' ~ settings.thumbnail_position|replace({ 'over-' : '' })
]
%}
{% spaceless %}
{% if settings.nav %}
<div{{attributes.addClass(classes,container)|without('id')}}>
{{ items }}
</div>
{% else %}
<div {{attributes.addClass(container)}}>
{{ items }}
</div>
{% endif %}
{% endspaceless %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment