diff --git a/config/install/core.entity_form_display.paragraph.pcb_button_group.default.yml b/config/install/core.entity_form_display.paragraph.pcb_button_group.default.yml new file mode 100644 index 0000000..e1e6149 --- /dev/null +++ b/config/install/core.entity_form_display.paragraph.pcb_button_group.default.yml @@ -0,0 +1,32 @@ +langcode: en +status: true +dependencies: + config: + - field.field.paragraph.pcb_button_group.field_pcb_button_group_container + - paragraphs.paragraphs_type.pcb_button_group + module: + - paragraphs + enforced: + module: + - paragraphs_collection_bootstrap +id: paragraph.pcb_button_group.default +targetEntityType: paragraph +bundle: pcb_button_group +mode: default +content: + field_pcb_button_group_container: + type: paragraphs + weight: 0 + settings: + title: Paragraph + title_plural: Paragraphs + edit_mode: open + add_mode: dropdown + form_display_mode: default + default_paragraph_type: '' + third_party_settings: { } + region: content +hidden: + created: true + status: true + uid: true \ No newline at end of file diff --git a/config/install/core.entity_view_display.paragraph.pcb_button_group.default.yml b/config/install/core.entity_view_display.paragraph.pcb_button_group.default.yml new file mode 100644 index 0000000..95e2f53 --- /dev/null +++ b/config/install/core.entity_view_display.paragraph.pcb_button_group.default.yml @@ -0,0 +1,26 @@ +langcode: en +status: true +dependencies: + config: + - field.field.paragraph.pcb_button_group.field_pcb_button_group_container + - paragraphs.paragraphs_type.pcb_button_group + module: + - entity_reference_revisions + enforced: + module: + - paragraphs_collection_bootstrap +id: paragraph.pcb_button_group.default +targetEntityType: paragraph +bundle: pcb_button_group +mode: default +content: + field_pcb_button_group_container: + type: entity_reference_revisions_entity_view + weight: 0 + label: hidden + settings: + view_mode: default + link: '' + third_party_settings: { } + region: content +hidden: { } \ No newline at end of file diff --git a/config/install/field.field.paragraph.pcb_button_group.field_pcb_button_group_container.yml b/config/install/field.field.paragraph.pcb_button_group.field_pcb_button_group_container.yml new file mode 100644 index 0000000..3960cfb --- /dev/null +++ b/config/install/field.field.paragraph.pcb_button_group.field_pcb_button_group_container.yml @@ -0,0 +1,32 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.paragraph.field_pcb_button_group_container + - paragraphs.paragraphs_type.pcb_button + - paragraphs.paragraphs_type.pcb_button_group + module: + - entity_reference_revisions + enforced: + module: + - paragraphs_collection_bootstrap +id: paragraph.pcb_button_group.field_pcb_button_group_container +field_name: field_pcb_button_group_container +entity_type: paragraph +bundle: pcb_button_group +label: Container +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + handler: 'default:paragraph' + handler_settings: + target_bundles: + pcb_button: pcb_button + target_bundles_drag_drop: + pcb_button: + enabled: true + weight: 31 +field_type: entity_reference_revisions \ No newline at end of file diff --git a/config/install/field.storage.paragraph.field_pcb_button_group_container.yml b/config/install/field.storage.paragraph.field_pcb_button_group_container.yml new file mode 100644 index 0000000..7689b48 --- /dev/null +++ b/config/install/field.storage.paragraph.field_pcb_button_group_container.yml @@ -0,0 +1,22 @@ +langcode: en +status: true +dependencies: + module: + - entity_reference_revisions + - paragraphs + enforced: + module: + - paragraphs_collection_bootstrap +id: paragraph.field_pcb_button_group_container +field_name: field_pcb_button_group_container +entity_type: paragraph +type: entity_reference_revisions +settings: + target_type: paragraph +module: entity_reference_revisions +locked: false +cardinality: -1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false \ No newline at end of file diff --git a/config/install/paragraphs.paragraphs_type.pcb_button_group.yml b/config/install/paragraphs.paragraphs_type.pcb_button_group.yml new file mode 100644 index 0000000..9f003d7 --- /dev/null +++ b/config/install/paragraphs.paragraphs_type.pcb_button_group.yml @@ -0,0 +1,20 @@ +langcode: en +status: true +dependencies: + module: + - paragraphs_collection + - paragraphs_collection_demo + enforced: + module: + - paragraphs_collection_bootstrap +id: pcb_button_group +label: 'Button group' +icon_uuid: null +description: 'Use Button group to add Bootstrap 4 button group component.' +behavior_plugins: + style: + group: '' + grid_layout: + paragraph_reference_field: '' + available_grid_layouts: { } + lockable: { } \ No newline at end of file diff --git a/paragraphs_collection_bootstrap.module b/paragraphs_collection_bootstrap.module index 1fe9de2..6a9f8a8 100644 --- a/paragraphs_collection_bootstrap.module +++ b/paragraphs_collection_bootstrap.module @@ -4,6 +4,7 @@ * @file * Contains paragraphs_collection_bootstrap.module. */ +use Drupal\paragraphs\Entity\Paragraph; /** * Implements hook_theme(). @@ -39,6 +40,18 @@ function paragraphs_collection_bootstrap_theme($existing, $type, $theme, $path) 'paragraph__pcb_jumbotron' => [ 'base hook' => 'paragraph', ], + 'paragraph__pcb_button_group' => [ + 'base hook' => 'paragraph', + ], + 'field__field_pcb_button_group_container' => [ + 'base hook' => 'field', + ], + 'field__paragraph__pcb_button_group__field_pcb_button_link' => [ + 'base hook' => 'field', + ], + 'paragraph__pcb_button_group__paragraph__pcb_button' => [ + 'base hook' => 'paragraph', + ], ]; } @@ -109,4 +122,28 @@ function paragraphs_collection_bootstrap_preprocess_paragraph(&$variables) { } } } -} \ No newline at end of file +} + +/** + * Implements hook_theme_suggestions_HOOK_alter(). + */ +function paragraphs_collection_bootstrap_theme_suggestions_field_alter(array &$suggestions, array $variables) { + if ($variables['element']['#object'] instanceof Paragraph) { + $object = $variables['element']['#object']; + if ($object->toArray()['parent_field_name'][0]['value'] == 'field_pcb_button_group_container') { + $suggestions[] = 'field__paragraph__pcb_button_group__field_pcb_button_link'; + } + } +} + +/** + * Implements hook_theme_suggestions_HOOK_alter(). + */ +function paragraphs_collection_bootstrap_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) { + if ($variables['elements']['#paragraph'] instanceof Paragraph) { + $object = $variables['elements']['#paragraph']; + if ($object->toArray()['parent_field_name'][0]['value'] == 'field_pcb_button_group_container') { + $suggestions[] = 'paragraph__pcb_button_group__paragraph__pcb_button'; + } + } +} diff --git a/templates/field--field-pcb-button-group-container.html.twig b/templates/field--field-pcb-button-group-container.html.twig new file mode 100644 index 0000000..3b4e59c --- /dev/null +++ b/templates/field--field-pcb-button-group-container.html.twig @@ -0,0 +1,50 @@ +{# +/** + * @file + * Default theme implementation for a field. + * + * To override output, copy the "field.html.twig" from the templates directory + * to your theme's directory and customize it, just like customizing other + * Drupal templates such as page.html.twig or node.html.twig. + * + * Instead of overriding the theming for all fields, you can also just override + * theming for a subset of fields using + * @link themeable Theme hook suggestions. @endlink For example, + * here are some theme hook suggestions that can be used for a field_foo field + * on an article node type: + * - field--node--field-foo--article.html.twig + * - field--node--field-foo.html.twig + * - field--node--article.html.twig + * - field--field-foo.html.twig + * - field--text-with-summary.html.twig + * - field.html.twig + * + * Available variables: + * - attributes: HTML attributes for the containing element. + * - label_hidden: Whether to show the field label or not. + * - title_attributes: HTML attributes for the title. + * - label: The label for the field. + * - multiple: TRUE if a field can contain multiple items. + * - items: List of all the field items. Each item contains: + * - attributes: List of HTML attributes for each item. + * - content: The field item's content. + * - entity_type: The entity type to which the field belongs. + * - field_name: The name of the field. + * - field_type: The type of the field. + * - label_display: The display settings for the label. + * + * @see template_preprocess_field() + * + * @ingroup themeable + */ +#} + +{% if label_hidden %} + {% for item in items %} + {{ item.content }} + {% endfor %} +{% else %} + {% for item in items %} + {{ item.content }} + {% endfor %} +{% endif %} \ No newline at end of file diff --git a/templates/field--paragraph--pcb-button-group--field-pcb-button-link.html.twig b/templates/field--paragraph--pcb-button-group--field-pcb-button-link.html.twig new file mode 100644 index 0000000..3b4e59c --- /dev/null +++ b/templates/field--paragraph--pcb-button-group--field-pcb-button-link.html.twig @@ -0,0 +1,50 @@ +{# +/** + * @file + * Default theme implementation for a field. + * + * To override output, copy the "field.html.twig" from the templates directory + * to your theme's directory and customize it, just like customizing other + * Drupal templates such as page.html.twig or node.html.twig. + * + * Instead of overriding the theming for all fields, you can also just override + * theming for a subset of fields using + * @link themeable Theme hook suggestions. @endlink For example, + * here are some theme hook suggestions that can be used for a field_foo field + * on an article node type: + * - field--node--field-foo--article.html.twig + * - field--node--field-foo.html.twig + * - field--node--article.html.twig + * - field--field-foo.html.twig + * - field--text-with-summary.html.twig + * - field.html.twig + * + * Available variables: + * - attributes: HTML attributes for the containing element. + * - label_hidden: Whether to show the field label or not. + * - title_attributes: HTML attributes for the title. + * - label: The label for the field. + * - multiple: TRUE if a field can contain multiple items. + * - items: List of all the field items. Each item contains: + * - attributes: List of HTML attributes for each item. + * - content: The field item's content. + * - entity_type: The entity type to which the field belongs. + * - field_name: The name of the field. + * - field_type: The type of the field. + * - label_display: The display settings for the label. + * + * @see template_preprocess_field() + * + * @ingroup themeable + */ +#} + +{% if label_hidden %} + {% for item in items %} + {{ item.content }} + {% endfor %} +{% else %} + {% for item in items %} + {{ item.content }} + {% endfor %} +{% endif %} \ No newline at end of file diff --git a/templates/paragraph--pcb-button-group--paragraph--pcb-button.html.twig b/templates/paragraph--pcb-button-group--paragraph--pcb-button.html.twig new file mode 100644 index 0000000..3d7d33d --- /dev/null +++ b/templates/paragraph--pcb-button-group--paragraph--pcb-button.html.twig @@ -0,0 +1,46 @@ +{# +/** + * @file + * Default theme implementation to display a paragraph. + * + * Available variables: + * - paragraph: Full paragraph entity. + * Only method names starting with "get", "has", or "is" and a few common + * methods such as "id", "label", and "bundle" are available. For example: + * - paragraph.getCreatedTime() will return the paragraph creation timestamp. + * - paragraph.id(): The paragraph ID. + * - paragraph.bundle(): The type of the paragraph, for example, "image" or "text". + * - paragraph.getOwnerId(): The user ID of the paragraph author. + * See Drupal\paragraphs\Entity\Paragraph for a full list of public properties + * and methods for the paragraph object. + * - content: All paragraph items. Use {{ content }} to print them all, + * or print a subset such as {{ content.field_example }}. Use + * {{ content|without('field_example') }} to temporarily suppress the printing + * of a given child element. + * - attributes: HTML attributes for the containing element. + * The attributes.class element may contain one or more of the following + * classes: + * - paragraphs: The current template type (also known as a "theming hook"). + * - paragraphs--type-[type]: The current paragraphs type. For example, if the paragraph is an + * "Image" it would result in "paragraphs--type--image". Note that the machine + * name will often be in a short form of the human readable label. + * - paragraphs--view-mode--[view_mode]: The View Mode of the paragraph; for example, a + * preview would result in: "paragraphs--view-mode--preview", and + * default: "paragraphs--view-mode--default". + * - view_mode: View mode; for example, "preview" or "full". + * - logged_in: Flag for authenticated user status. Will be true when the + * current user is a logged-in member. + * - is_admin: Flag for admin user status. Will be true when the current user + * is an administrator. + * + * @see template_preprocess_paragraph() + * + * @ingroup themeable + */ +#} + +{% block paragraph %} + {% block content %} + {{ content }} + {% endblock %} +{% endblock paragraph %} diff --git a/templates/paragraph--pcb-button-group.html.twig b/templates/paragraph--pcb-button-group.html.twig new file mode 100644 index 0000000..7391792 --- /dev/null +++ b/templates/paragraph--pcb-button-group.html.twig @@ -0,0 +1,51 @@ +{% extends "@paragraphs/paragraph.html.twig" %} +{# +/** + * @file + * Theme override for a paragraph content. + * + * Available variables: + * - paragraph: Full paragraph entity. + * Only method names starting with "get", "has", or "is" and a few common + * methods such as "id", "label", and "bundle" are available. For example: + * - paragraph.getCreatedTime() will return the paragraph creation timestamp. + * - paragraph.id(): The paragraph ID. + * - paragraph.bundle(): The type of the paragraph, for example, "image" or "text". + * - paragraph.getOwnerId(): The user ID of the paragraph author. + * See Drupal\paragraphs\Entity\Paragraph for a full list of public properties + * and methods for the paragraph object. + * - content: All paragraph items. Use {{ content }} to print them all, + * or print a subset such as {{ content.field_example }}. Use + * {{ content|without('field_example') }} to temporarily suppress the printing + * of a given child element. + * - attributes: HTML attributes for the containing element. + * The attributes.class element may contain one or more of the following + * classes: + * - paragraphs: The current template type (also known as a "theming hook"). + * - paragraphs--type-[type]: The current paragraphs type. For example, if the paragraph is an + * "Image" it would result in "paragraphs--type--image". Note that the machine + * name will often be in a short form of the human readable label. + * - paragraphs--view-mode--[view_mode]: The View Mode of the paragraph; for example, a + * preview would result in: "paragraphs--view-mode--preview", and + * default: "paragraphs--view-mode--default". + * - view_mode: View mode; for example, "preview" or "full". + * - logged_in: Flag for authenticated user status. Will be true when the + * current user is a logged-in member. + * - is_admin: Flag for admin user status. Will be true when the current user + * is an administrator. + * + * @see template_preprocess_paragraph() + * + * @ingroup themeable +*/ +#} + +{% block paragraph %} +
+ {% block content %} + {% if content.field_pcb_button_group_container %} + {{ content.field_pcb_button_group_container }} + {% endif %} + {% endblock %} +
+{% endblock paragraph %}