Refactor to use a Post class

References #78
This commit is contained in:
Oliver Davies 2020-05-29 21:35:21 +01:00
parent 79eb9bef0b
commit 165b6e8195
7 changed files with 88 additions and 7 deletions

View file

@ -5,20 +5,22 @@
* Functions to support theming in the Tailwind CSS theme.
*/
use Drupal\custom\Entity\Node\Post;
/**
* Implements hook_preprocess_HOOK().
*/
function opdavies_preprocess_page(array &$variables): void {
/** @var \Drupal\Core\Entity\EntityInterface $node */
if (!$node = \Drupal::routeMatch()->getParameter('node')) {
/** @var \Drupal\custom\Entity\Node\Post $node */
if (!$node = $variables['node']) {
return;
}
if ($node->getType() != 'post') {
if (!$node instanceof Post) {
return;
}
if ($node->get('field_has_tweet')->getString()) {
if ($node->hasTweet()) {
$variables['#attached']['library'][] = 'opdavies/twitter';
}
}