Created
January 19, 2017 09:05
-
-
Save DuaelFr/4dc09e800b17fd6ff49507e03b69746e to your computer and use it in GitHub Desktop.
Disable page title from a paragraph setting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Helper to hide the page title (see THEME_preprocess_page). | |
| */ | |
| function _feature_commons_hide_title($value = NULL) { | |
| $static = &drupal_static(__FUNCTION__, FALSE); | |
| if (NULL !== $value) { | |
| $static = (bool) $value; | |
| } | |
| return $static; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Implements hook_preprocess_entity(). | |
| */ | |
| function feature_pages_preprocess_entity(&$variables) { | |
| if ($variables['entity_type'] != 'paragraphs_item' || $variables['view_mode'] == 'paragraphs_editor_preview') { | |
| return; | |
| } | |
| $entity = $variables['paragraphs_item']; | |
| switch ($entity->bundle) { | |
| // ... | |
| // For "Titre" bundle. | |
| case 'title': | |
| // Wrap title into <hX>. | |
| $depth = $entity->field_title_depth[LANGUAGE_NONE][0]['value']; | |
| $variables['content']['field_title'][0]['#prefix'] = '<h' . $depth . '>'; | |
| $variables['content']['field_title'][0]['#suffix'] = '</h' . $depth . '>'; | |
| if ($depth == 1) { | |
| _feature_commons_hide_title(TRUE); | |
| } | |
| break; | |
| // ... | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Override or insert variables into the page templates. | |
| * | |
| * @param $variables | |
| * An array of variables to pass to the theme template. | |
| * @param $hook | |
| * The name of the template being rendered ("page" in this case.) | |
| */ | |
| function THEME_preprocess_page(&$variables, $hook) { | |
| if (module_exists('feature_commons') && _feature_commons_hide_title()) { | |
| $variables['title'] = ''; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment