diff --git a/modules/custom/d_block/config/install/core.entity_form_display.paragraph.d_p_block.default.yml b/modules/custom/d_block/config/install/core.entity_form_display.paragraph.d_p_block.default.yml index 5e9bc9eae..9708ecad8 100644 --- a/modules/custom/d_block/config/install/core.entity_form_display.paragraph.d_p_block.default.yml +++ b/modules/custom/d_block/config/install/core.entity_form_display.paragraph.d_p_block.default.yml @@ -15,59 +15,61 @@ third_party_settings: children: - group_basic - group_settings + label: Tabs + region: content parent_name: '' weight: 0 format_type: tabs - region: content format_settings: - id: '' classes: '' + id: '' direction: horizontal - label: Tabs group_basic: children: - field_block + label: Basic + region: content parent_name: group_tabs weight: 5 format_type: tab - region: content format_settings: - id: '' classes: '' - description: '' + id: '' formatter: open + description: '' required_fields: true - label: Basic group_settings: children: - field_d_settings + label: Settings + region: content parent_name: group_tabs weight: 6 format_type: tab - region: content format_settings: - id: '' classes: '' - description: '' + id: '' formatter: closed + description: '' required_fields: true - label: Settings id: paragraph.d_p_block.default targetEntityType: paragraph bundle: d_p_block mode: default content: field_block: + type: d_block_field_default weight: 1 + region: content settings: plugin_id: '' settings: { } configuration_form: full third_party_settings: { } - type: d_block_field_default - region: content field_d_settings: + type: field_d_p_set_settings weight: 7 + region: content settings: filter_mode: '1' allowed_settings: @@ -121,8 +123,6 @@ content: column_count: status: 0 third_party_settings: { } - type: field_d_p_set_settings - region: content hidden: created: true status: true diff --git a/modules/custom/d_block/config/install/core.entity_view_mode.block.token.yml b/modules/custom/d_block/config/install/core.entity_view_mode.block.token.yml index 02287c299..19d05d8e7 100644 --- a/modules/custom/d_block/config/install/core.entity_view_mode.block.token.yml +++ b/modules/custom/d_block/config/install/core.entity_view_mode.block.token.yml @@ -5,5 +5,6 @@ dependencies: - block id: block.token label: Token +description: '' targetEntityType: block cache: true diff --git a/modules/custom/d_block/config/install/field.field.paragraph.d_p_block.field_block.yml b/modules/custom/d_block/config/install/field.field.paragraph.d_p_block.field_block.yml index dad15b2ab..210a18b5e 100644 --- a/modules/custom/d_block/config/install/field.field.paragraph.d_p_block.field_block.yml +++ b/modules/custom/d_block/config/install/field.field.paragraph.d_p_block.field_block.yml @@ -17,5 +17,21 @@ translatable: false default_value: { } default_value_callback: '' settings: - plugin_ids: { } + plugin_categories: + 'Chaos Tools': 'Chaos Tools' + Block: 0 + 'Content block': 0 + core: 0 + 'Droopler Social Media Block': 0 + 'Drupal 8 Mega Menu': 0 + Facets: 0 + Forms: 0 + Help: 0 + 'Lists (Views)': 0 + Menus: 0 + Search: 0 + System: 0 + User: 0 + Views: 0 + plugin_categories_exclude: 1 field_type: d_block_field diff --git a/modules/custom/d_block/d_block.info.yml b/modules/custom/d_block/d_block.info.yml index 361098ee6..6a7a34a4a 100644 --- a/modules/custom/d_block/d_block.info.yml +++ b/modules/custom/d_block/d_block.info.yml @@ -3,34 +3,34 @@ core_version_requirement: ^10 description: 'Provides "Block" paragraph and related configuration. It allows you to insert blocks into paragraphs.' type: module dependencies: - - droopler:d_block_field - - droopler:d_content - - droopler:d_p - - droopler:d_p_banner - - droopler:d_p_carousel - - droopler:d_p_counters - - droopler:d_p_form - - droopler:d_p_gallery - - droopler:d_p_reference_content - - droopler:d_p_side_by_side - - droopler:d_p_side_embed - - droopler:d_p_side_image - - droopler:d_p_side_tiles - - droopler:d_p_subscribe_file - - droopler:d_p_text_blocks - - droopler:d_p_text_paged - - droopler:d_p_text_with_bckg - - droopler:d_p_tiles - - droopler:d_social_media - - droopler:d_update - - drupal:block - - drupal:block_content - - drupal:field - - drupal:language - - drupal:system - - entity_reference_revisions:entity_reference_revisions - - paragraphs:paragraphs - -package: Droopler Paragraphs + - 'droopler:d_block_field' + - 'droopler:d_content' + - 'droopler:d_p' + - 'droopler:d_p_banner' + - 'droopler:d_p_carousel' + - 'droopler:d_p_counters' + - 'droopler:d_p_form' + - 'droopler:d_p_gallery' + - 'droopler:d_p_reference_content' + - 'droopler:d_p_side_by_side' + - 'droopler:d_p_side_embed' + - 'droopler:d_p_side_image' + - 'droopler:d_p_side_tiles' + - 'droopler:d_p_subscribe_file' + - 'droopler:d_p_text_blocks' + - 'droopler:d_p_text_paged' + - 'droopler:d_p_text_with_bckg' + - 'droopler:d_p_tiles' + - 'droopler:d_social_media' + - 'droopler:d_update' + - 'drupal:block' + - 'drupal:block_content' + - 'drupal:field' + - 'drupal:language' + - 'drupal:system' + - 'entity_reference_revisions:entity_reference_revisions' + - 'field_group:field_group' + - 'paragraphs:paragraphs' +package: 'Droopler Paragraphs' version: DROOPLER_VERSION core_incompatible: false diff --git a/modules/custom/d_block_field/src/Plugin/Field/FieldFormatter/BlockFieldFormatter.php b/modules/custom/d_block_field/src/Plugin/Field/FieldFormatter/BlockFieldFormatter.php index 063e89403..4a5b47eff 100644 --- a/modules/custom/d_block_field/src/Plugin/Field/FieldFormatter/BlockFieldFormatter.php +++ b/modules/custom/d_block_field/src/Plugin/Field/FieldFormatter/BlockFieldFormatter.php @@ -167,6 +167,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $this->renderer->addCacheableDependency($elements[$delta], $block_instance); } + return $elements; } diff --git a/modules/custom/d_block_field/src/Plugin/Field/FieldType/BlockFieldItem.php b/modules/custom/d_block_field/src/Plugin/Field/FieldType/BlockFieldItem.php index 40c22eac6..89105ec3c 100644 --- a/modules/custom/d_block_field/src/Plugin/Field/FieldType/BlockFieldItem.php +++ b/modules/custom/d_block_field/src/Plugin/Field/FieldType/BlockFieldItem.php @@ -28,7 +28,8 @@ class BlockFieldItem extends FieldItemBase implements BlockFieldItemInterface { */ public static function defaultFieldSettings() { return [ - 'plugin_ids' => [], + 'plugin_categories' => [], + 'plugin_categories_exclude' => FALSE, ] + parent::defaultFieldSettings(); } @@ -75,6 +76,33 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) ]; } + /** + * {@inheritdoc} + */ + public function fieldSettingsForm(array $form, FormStateInterface $form_state) { + $categories = \Drupal::service('plugin.manager.block')->getCategories(); + foreach ($categories as $category) { + $category_name = (string) $category; + $options[$category_name] = $category_name; + } + + $element['plugin_categories'] = [ + '#title' => $this->t('Plugins categories'), + '#description' => $this->t('Leave empty to allow all plugin categories.'), + '#type' => 'checkboxes', + '#options' => $options ?? [], + '#default_value' => $this->getSetting('plugin_categories'), + ]; + $element['plugin_categories_exclude'] = [ + '#title' => $this->t('Exclude selected categories'), + '#description' => $this->t('If unchecked, only plugins from selected categories will be available. If checked, plugins from selected categories will be excluded.'), + '#type' => 'checkbox', + '#default_value' => $this->getSetting('plugin_categories_exclude'), + ]; + + return $element; + } + /** * {@inheritdoc} */ @@ -136,18 +164,4 @@ public function getBlock() { return $block_instance; } - /** - * Validates plugin_ids table select element. - */ - public static function validatePluginIds(array &$element, FormStateInterface $form_state, &$complete_form) { - $value = array_filter($element['#value']); - if (array_keys($element['#options']) == array_keys($value)) { - $form_state->setValueForElement($element, []); - } - else { - $form_state->setValueForElement($element, $value); - } - return $element; - } - } diff --git a/modules/custom/d_block_field/src/Plugin/Field/FieldWidget/BlockFieldWidget.php b/modules/custom/d_block_field/src/Plugin/Field/FieldWidget/BlockFieldWidget.php index fc650f145..cb3a7c3d0 100644 --- a/modules/custom/d_block_field/src/Plugin/Field/FieldWidget/BlockFieldWidget.php +++ b/modules/custom/d_block_field/src/Plugin/Field/FieldWidget/BlockFieldWidget.php @@ -162,11 +162,17 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $item->settings = $item->settings ?: []; } + $categories = array_filter($this->getFieldSetting('plugin_categories')); + $categories_exclude = $this->getFieldSetting('plugin_categories_exclude'); + $options = []; $definitions = $this->fieldManager->getBlockDefinitions(); foreach ($definitions as $id => $definition) { $category = (string) $definition['category']; - $options[$category][$id] = $definition['admin_label']; + + if (empty($categories) || ($categories_exclude xor in_array($category, $categories))) { + $options[$category][$id] = $definition['admin_label']; + } } // Make sure the plugin id is allowed, if not clear all settings.