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
// Load block and render | |
$socialNetworksBlock = \Drupal\block_content\Entity\BlockContent::load(7); | |
$variables['social_networks'] = \Drupal::entityTypeManager() | |
->getViewBuilder('block_content') | |
->view($socialNetworksBlock); | |
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
// Load a node | |
$listing_page_node = \Drupal\node\Entity\Node::load($node_id); | |
// Get current node from the route | |
\Drupal::routeMatch()->getParameter('node') | |
\Drupal::routeMatch()->getParameter('node')->getType() | |
// Get node in PHP and get field | |
if(\Drupal::routeMatch()->getParameters()->has('node')) { | |
$current_node = \Drupal::routeMatch()->getParameter('node'); |
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
//PAGE Suggestions | |
$suggestions[] = 'page__path_alias__' . formatPathAlias($path_alias); | |
//NODE Suggestions | |
$node = \Drupal::request()->attributes->get('node'); | |
if (!is_null($node)) { | |
$node_alias = \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$node->id()); | |
$view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); | |
$suggestions[] = 'node__path_alias__' . formatPathAlias($path_alias) . '__' . $view_mode; |
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
$current_path = \Drupal::service('path.current')->getPath(); | |
\Drupal::service('path.alias_manager')->getAliasByPath($current_path); |
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
// file at src/EventSubscriber/RedirectNodesSubscriber.php | |
<?php | |
/** | |
* @file | |
* Contains \Drupal\redirect_nodes\EventSubscriber\RedirectNodesSubscriber | |
*/ | |
namespace Drupal\redirect_nodes\EventSubscriber; | |
use Drupal\Core\Url; |
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
function mytheme_preprocess_html(&$variables) { | |
// truncate <title> to 58 characters, including the brand | |
$title_length = strlen($variables['head_title']['title']); | |
$ti_str_limit = 58; | |
$title_suffix = ' | My Company, LLC.'; | |
$suffix_length = strlen($title_suffix); | |
$allowable_length = $ti_str_limit - $suffix_length; | |
$allowable_length_w_ellipse = $allowable_length - 3; | |
if (strpos($variables['head_title']['title'], $title_suffix) == false) { |
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
function mytheme_page_attachments_alter(array &$attachments) { | |
if (in_array('core/jquery', $attachments['#attached']['library'])) { | |
$index = array_search('core/jquery', $attachments['#attached']['library']); | |
unset($attachments['#attached']['library'][$index]); | |
} | |
} |
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
{{ (content.field_benefits | field_value)[0]['#paragraph'].get('field_accordion') | length }} |
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
{% set index_of_paragraph = content.field_summary['#object']._referringItem.getName() %} |
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
function example_preprocess_node(&$variables) { | |
$node = $variables['node']; | |
$paragraph = $node->field_paragraph_example->entity; | |
$nested_paragraph = $paragraph->field_another_paragraph_ref->entity; | |
$term = $nested_paragraph->field_example_term_ref->entity; | |
// The following simple syntax works when you just need the first value of the field: | |
$textfield_value_on_term = $term->field_exampletext_on_term->value; | |
} |