Skip to content

Commit

Permalink
Merge pull request #279 from UN-OCHA/berliner/HPC-9927
Browse files Browse the repository at this point in the history
HPC-9927: Fix handling of column setting on paragraphs
  • Loading branch information
berliner authored Nov 26, 2024
2 parents 796220e + 137ad48 commit f947eb6
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions html/modules/custom/ncms_ui/ncms_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use Drupal\ncms_ui\Entity\Media\Video;
use Drupal\ncms_ui\Entity\Taxonomy\ContentSpace;
use Drupal\ncms_ui\Form\ContentSpaceSelectForm;
use Drupal\node\NodeInterface;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\user\Entity\User;
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\Plugin\views\query\QueryPluginBase;
Expand Down Expand Up @@ -299,6 +300,24 @@ function ncms_ui_preprocess_node(&$variables) {
}
}

/**
* Implements hook_preprocess_hook().
*/
function ncms_ui_preprocess_field(&$variables) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $variables['element']['#object'];
if ($entity instanceof Paragraph) {
if ($entity->hasField('field_columns')) {
$columns_field = $entity->get('field_columns');
if ($columns_field->isEmpty()) {
$columns_field->applyDefaultValue();
}
$columns = $columns_field->value;
$variables['attributes']['class'][] = 'col-' . $columns;
}
}
}

/**
* Implements hook_preprocess_hook().
*/
Expand All @@ -315,22 +334,6 @@ function ncms_ui_preprocess_field__paragraph__field_title__document_chapter(&$va
}
}

/**
* Implements hook_preprocess_hook().
*/
function ncms_ui_preprocess_field__paragraph(&$variables, $original_hook) {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $variables['element']['#object'];
if ($paragraph->hasField('field_columns')) {
$columns_field = $paragraph->get('field_columns');
if ($columns_field->isEmpty()) {
$columns_field->applyDefaultValue();
}
$columns = $columns_field->value;
$variables['attributes']['class'][] = 'col-' . $columns;
}
}

/**
* Implements hook_preprocess_layout_paragraphs_builder_controls().
*/
Expand Down

0 comments on commit f947eb6

Please sign in to comment.