Include widgets.js on blog posts that need it

Fixes #78
This commit is contained in:
Oliver Davies 2020-05-29 21:05:17 +01:00
parent 22533eba56
commit 79eb9bef0b
7 changed files with 90 additions and 0 deletions

View file

@ -5,6 +5,7 @@ dependencies:
config:
- field.field.node.post.body
- field.field.node.post.field_excerpt
- field.field.node.post.field_has_tweet
- field.field.node.post.field_images
- field.field.node.post.field_series
- field.field.node.post.field_tags
@ -42,6 +43,13 @@ content:
third_party_settings: { }
type: string_textarea
region: content
field_has_tweet:
weight: 26
settings:
display_label: true
third_party_settings: { }
type: boolean_checkbox
region: content
field_images:
weight: 9
settings:

View file

@ -5,6 +5,7 @@ dependencies:
config:
- field.field.node.post.body
- field.field.node.post.field_excerpt
- field.field.node.post.field_has_tweet
- field.field.node.post.field_images
- field.field.node.post.field_series
- field.field.node.post.field_tags
@ -24,6 +25,16 @@ content:
settings: { }
third_party_settings: { }
region: content
field_has_tweet:
weight: 3
label: above
settings:
format: default
format_custom_false: ''
format_custom_true: ''
third_party_settings: { }
type: boolean
region: content
field_tags:
weight: 2
label: above

View file

@ -6,6 +6,7 @@ dependencies:
- core.entity_view_mode.node.teaser
- field.field.node.post.body
- field.field.node.post.field_excerpt
- field.field.node.post.field_has_tweet
- field.field.node.post.field_images
- field.field.node.post.field_series
- field.field.node.post.field_tags
@ -31,6 +32,7 @@ content:
third_party_settings: { }
hidden:
body: true
field_has_tweet: true
field_images: true
field_series: true
field_tags: true

View file

@ -0,0 +1,23 @@
uuid: e9be005a-2f67-4204-ba80-72a74e7f990b
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_has_tweet
- node.type.post
id: node.post.field_has_tweet
field_name: field_has_tweet
entity_type: node
bundle: post
label: 'Has tweet'
description: 'Check to include Twitter''s widget.js script for this page.'
required: false
translatable: false
default_value:
-
value: 0
default_value_callback: ''
settings:
on_label: 'Yes'
off_label: 'No'
field_type: boolean

View file

@ -0,0 +1,18 @@
uuid: f0ab9755-e7d4-4b86-b4f5-df0472c727dd
langcode: en
status: true
dependencies:
module:
- node
id: node.field_has_tweet
field_name: field_has_tweet
entity_type: node
type: boolean
settings: { }
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

View file

@ -2,6 +2,16 @@ global-styling:
css:
base:
dist/tailwind.css: {}
global-scripts:
js:
dist/js/app.js: {}
twitter:
js:
https://platform.twitter.com/widgets.js:
type: external
minified: true
attributes:
async: true
charset: 'utf-8'

View file

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