diff --git a/layout_builder_enhancements.info.yml b/layout_builder_enhancements.info.yml index 9a1a339243598e9d998255e9a66fb7ac5d5019ac..8e7309b672886a1d3936af33a65b822740aea73c 100644 --- a/layout_builder_enhancements.info.yml +++ b/layout_builder_enhancements.info.yml @@ -1,7 +1,7 @@ name: 'Layout Builder Enhancements' type: module description: 'Add some functionality for layout builder.' -core_version_requirement: ^8 || ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 package: 'Layout' dependencies: - drupal:layout_builder diff --git a/modules/layout_builder_enhancements_blocks/layout_builder_enhancements_blocks.info.yml b/modules/layout_builder_enhancements_blocks/layout_builder_enhancements_blocks.info.yml index 7cbfb609284a3ff6adfda60187fd2ccc1ce1f6d9..546484e9981b6f570840bb39b0b62a6ba38032b3 100644 --- a/modules/layout_builder_enhancements_blocks/layout_builder_enhancements_blocks.info.yml +++ b/modules/layout_builder_enhancements_blocks/layout_builder_enhancements_blocks.info.yml @@ -1,7 +1,7 @@ -name: 'LBE - Blocks' +name: 'Layout Builder Enhancements - Blocks' type: module description: 'Add category, weight and icon to inline blocks' -core_version_requirement: ^8 || ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 package: 'Layout' dependencies: - layout_builder_enhancements:layout_builder_enhancements diff --git a/modules/layout_builder_enhancements_blocks/src/Controller/ChooseBlockController.php b/modules/layout_builder_enhancements_blocks/src/Controller/ChooseBlockController.php index 9fff2dba2d4a80058b5c17fea09d9fd5b172e57a..d4ffe94f30e545052a2c53db7a99f57c01d08181 100644 --- a/modules/layout_builder_enhancements_blocks/src/Controller/ChooseBlockController.php +++ b/modules/layout_builder_enhancements_blocks/src/Controller/ChooseBlockController.php @@ -2,8 +2,13 @@ namespace Drupal\layout_builder_enhancements_blocks\Controller; +use Drupal\Core\Block\BlockManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\layout_builder\SectionStorageInterface; use Drupal\layout_builder\Controller\ChooseBlockController as BaseController; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a controller to choose a new block. @@ -13,6 +18,42 @@ use Drupal\layout_builder\Controller\ChooseBlockController as BaseController; */ class ChooseBlockController extends BaseController { + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * ChooseBlockController constructor. + * + * @param \Drupal\Core\Block\BlockManagerInterface $block_manager + * The block manager. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current user. + * @param ModuleHandlerInterface $module_handler + * The module handler. + */ + public function __construct(BlockManagerInterface $block_manager, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, ModuleHandlerInterface $module_handler) { + parent::__construct($block_manager, $entity_type_manager, $current_user); + $this->moduleHandler = $module_handler; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.block'), + $container->get('entity_type.manager'), + $container->get('current_user'), + $container->get('module_handler') + ); + } + /** * Provides the UI for choosing a new block. * @@ -26,6 +67,7 @@ class ChooseBlockController extends BaseController { * @return array * A render array. */ + #[\Override] public function build(SectionStorageInterface $section_storage, int $delta, $region) { $build = parent::build($section_storage, $delta, $region); $inline_blocks = $this->inlineBlockList($section_storage, $delta, $region); @@ -80,11 +122,13 @@ class ChooseBlockController extends BaseController { * @return array * A render array. */ + #[\Override] public function inlineBlockList(SectionStorageInterface $section_storage, int $delta, $region) { $build = parent::inlineBlockList($section_storage, $delta, $region); $restriction_plugins = []; - if (\Drupal::service('module_handler')->moduleExists('layout_builder_restrictions')) { + if ($this->moduleHandler->moduleExists('layout_builder_restrictions')) { + // @phpstan-ignore-next-line $layout_builder_restrictions_manager = \Drupal::service('plugin.manager.layout_builder_restriction'); $restriction_plugins = $layout_builder_restrictions_manager->getSortedPlugins(); } diff --git a/modules/layout_builder_enhancements_blocks/src/Routing/RouteSubscriber.php b/modules/layout_builder_enhancements_blocks/src/Routing/RouteSubscriber.php index 5bee278cfd6e4add4982115ba09e85da9b402b22..52187f313cbbb6ce5f0054c5a6a3c8bcc6acb719 100644 --- a/modules/layout_builder_enhancements_blocks/src/Routing/RouteSubscriber.php +++ b/modules/layout_builder_enhancements_blocks/src/Routing/RouteSubscriber.php @@ -14,6 +14,7 @@ class RouteSubscriber extends RouteSubscriberBase { /** * {@inheritdoc} */ + #[\Override] protected function alterRoutes(RouteCollection $collection) { if ($route = $collection->get('layout_builder.choose_block')) { $route->setDefault('_controller', '\Drupal\layout_builder_enhancements_blocks\Controller\ChooseBlockController::build'); @@ -23,7 +24,8 @@ class RouteSubscriber extends RouteSubscriberBase { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + #[\Override] + public static function getSubscribedEvents(): array { $events[RoutingEvents::ALTER] = ['onAlterRoutes', -110]; return $events; } diff --git a/modules/layout_builder_enhancements_views/config/schema/layout_builder_enhancements_views.schema.yml b/modules/layout_builder_enhancements_views/config/schema/layout_builder_enhancements_views.schema.yml index 89aa4c6134876b231e2d6183f0a094f0b5e3da69..db785dff8e649165c8717fa77804484ba3ef83c2 100644 --- a/modules/layout_builder_enhancements_views/config/schema/layout_builder_enhancements_views.schema.yml +++ b/modules/layout_builder_enhancements_views/config/schema/layout_builder_enhancements_views.schema.yml @@ -1,4 +1,4 @@ -block.settings.layout_builder_enhancements_view_block:*: +block.settings.layout_builder_enhancements_view_block: type: block_settings label: 'Entity Browser block' mapping: @@ -13,13 +13,24 @@ block.settings.layout_builder_enhancements_view_block:*: label: 'Allowed View Modes' show_footer: type: boolean - label: Label Display + label: Show footer areas show_pager: type: boolean - label: Label Display + label: Show pager show_header: type: boolean - label: Label Display + label: Show header areas + show_all: + type: boolean + label: Show all remaining rows respect_pager: type: boolean - label: Label Display + label: Should respect the pager + +views.display.inline: + type: views_display + label: 'Inline display options' + +core.entity_view_display.node.landingpage.default:third_party_settings.layout_builder.sections.*.components.*.configuration.show_all: + type: boolean + label: boolean diff --git a/modules/layout_builder_enhancements_views/layout_builder_enhancements_views.info.yml b/modules/layout_builder_enhancements_views/layout_builder_enhancements_views.info.yml index 9707c6fa9688ae9224a290e549a4de3232ce67ce..b6a89e97cec9b860c8abce0068717160eed0823e 100644 --- a/modules/layout_builder_enhancements_views/layout_builder_enhancements_views.info.yml +++ b/modules/layout_builder_enhancements_views/layout_builder_enhancements_views.info.yml @@ -1,7 +1,7 @@ -name: 'Layout Builder Enhancements' +name: 'Layout Builder Enhancements - Views' type: module description: 'Add some functionality for layout builder.' -core_version_requirement: ^8 || ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 package: 'Layout' dependencies: - layout_builder_enhancements:layout_builder_enhancements diff --git a/modules/layout_builder_enhancements_views/src/EventSubscriber/ViewEventSubscriber.php b/modules/layout_builder_enhancements_views/src/EventSubscriber/ViewEventSubscriber.php index 6563c8ac74c165f1245635ca5598f4ea5bbdb57c..ea44dcebb8eeff86d354a385a59a4f38354aa7f5 100644 --- a/modules/layout_builder_enhancements_views/src/EventSubscriber/ViewEventSubscriber.php +++ b/modules/layout_builder_enhancements_views/src/EventSubscriber/ViewEventSubscriber.php @@ -18,7 +18,8 @@ class ViewEventSubscriber implements EventSubscriberInterface { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + #[\Override] + public static function getSubscribedEvents(): array { return [ LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY => [ 'onBuildRender', @@ -57,6 +58,7 @@ class ViewEventSubscriber implements EventSubscriberInterface { * The offset for this block. */ protected function getOffset(SectionComponentBuildRenderArrayEvent $event, ViewBlock $block): int { + $contexts = $event->getContexts(); $weights =& \drupal_static(__FUNCTION__); $counter =& \drupal_static(__FUNCTION__ . '_counter', []); $component = $event->getComponent(); @@ -76,7 +78,6 @@ class ViewEventSubscriber implements EventSubscriberInterface { } if (!isset($weights[$block->getDerivativeId()])) { $weights[$block->getDerivativeId()] = []; - $contexts = $event->getContexts(); $sections = $this->getEntitySections($entity); foreach ($sections as $section) { diff --git a/modules/layout_builder_enhancements_views/src/Plugin/Block/ViewBlock.php b/modules/layout_builder_enhancements_views/src/Plugin/Block/ViewBlock.php index 03ba15449c437343bd3356c731b2a7fbdfa8e740..69036d2d3a034ac191bcbf354506846d20a2b9df 100644 --- a/modules/layout_builder_enhancements_views/src/Plugin/Block/ViewBlock.php +++ b/modules/layout_builder_enhancements_views/src/Plugin/Block/ViewBlock.php @@ -3,6 +3,7 @@ namespace Drupal\layout_builder_enhancements_views\Plugin\Block; use Drupal\Core\Block\BlockBase; +use Drupal\Core\Routing\CurrentRouteMatch; use Drupal\views\ResultRow; use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Cache\Cache; @@ -37,6 +38,10 @@ class ViewBlock extends BlockBase implements ContainerFactoryPluginInterface, Bl protected $resultCount = 0; protected $view; + /** + * @var \Drupal\Core\Routing\CurrentRouteMatch + */ + protected $currentRouteMatch; /** * {@inheritdoc} @@ -47,7 +52,8 @@ class ViewBlock extends BlockBase implements ContainerFactoryPluginInterface, Bl $plugin_definition, EntityTypeManagerInterface $manager, EntityDisplayRepositoryInterface $display_repository, - RendererInterface $renderer + RendererInterface $renderer, + CurrentRouteMatch $route_match ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->manager = $manager->getStorage('view'); @@ -55,12 +61,14 @@ class ViewBlock extends BlockBase implements ContainerFactoryPluginInterface, Bl $this->displayRepository = $display_repository; $this->renderer = $renderer; $this->view = $this->manager->load($this->getViewId()); + $this->currentRouteMatch = $route_match; } /** * {@inheritdoc} */ + #[\Override] public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, @@ -68,7 +76,8 @@ class ViewBlock extends BlockBase implements ContainerFactoryPluginInterface, Bl $plugin_definition, $container->get('entity_type.manager'), $container->get('entity_display.repository'), - $container->get('renderer') + $container->get('renderer'), + $container->get('current_route_match') ); } @@ -82,6 +91,7 @@ class ViewBlock extends BlockBase implements ContainerFactoryPluginInterface, Bl /** * {@inheritdoc} */ + #[\Override] public function build() { if ($this->offset == -1) { return []; @@ -181,6 +191,7 @@ class ViewBlock extends BlockBase implements ContainerFactoryPluginInterface, Bl /** * {@inheritdoc} */ + #[\Override] public function defaultConfiguration() { return [ 'label_display' => FALSE, @@ -210,11 +221,11 @@ class ViewBlock extends BlockBase implements ContainerFactoryPluginInterface, Bl 'layout_builder.update_block', 'layout_builder.remove_block' ]; - if (in_array(\Drupal::routeMatch()->getRouteName(), $routes)) { + if (in_array($this->currentRouteMatch->getRouteName(), $routes)) { /** * @var OverridesSectionStorage */ - $storage = \Drupal::routeMatch()->getParameter('section_storage'); + $storage = $this->currentRouteMatch->getParameter('section_storage'); /** * @var $entity ContentEntityBas */ @@ -262,6 +273,7 @@ class ViewBlock extends BlockBase implements ContainerFactoryPluginInterface, Bl /** * {@inheritdoc} */ + #[\Override] public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); @@ -352,6 +364,7 @@ class ViewBlock extends BlockBase implements ContainerFactoryPluginInterface, Bl /** * {@inheritdoc} */ + #[\Override] public function blockSubmit($form, FormStateInterface $form_state) { parent::blockSubmit($form, $form_state); $values = $form_state->getValues(); diff --git a/modules/layout_builder_enhancements_views/src/Plugin/Derivative/ViewBlock.php b/modules/layout_builder_enhancements_views/src/Plugin/Derivative/ViewBlock.php index 42f6c638000d9838d5e9f9e4c2e0decdf01fb402..e49ca389c310275aebdd194ce5b703be36d52106 100644 --- a/modules/layout_builder_enhancements_views/src/Plugin/Derivative/ViewBlock.php +++ b/modules/layout_builder_enhancements_views/src/Plugin/Derivative/ViewBlock.php @@ -24,6 +24,7 @@ class ViewBlock extends DeriverBase implements ContainerDeriverInterface { /** * {@inheritdoc} */ + #[\Override] public function getDerivativeDefinitions($base_plugin_definition) { $views = Views::getViewsAsOptions(FALSE, 'enabled'); $entity_ids = $this->manager->getQuery() @@ -82,6 +83,7 @@ class ViewBlock extends DeriverBase implements ContainerDeriverInterface { /** * {@inheritdoc} */ + #[\Override] public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $container->get('entity_type.manager') diff --git a/modules/layout_builder_enhancements_views/src/Plugin/views/display/Inline.php b/modules/layout_builder_enhancements_views/src/Plugin/views/display/Inline.php index 19517c6553458cceed1d3fe93346ee2c54a9c234..cb6188ed9491c1811f833f9e8e9f4979a50d87b7 100644 --- a/modules/layout_builder_enhancements_views/src/Plugin/views/display/Inline.php +++ b/modules/layout_builder_enhancements_views/src/Plugin/views/display/Inline.php @@ -2,6 +2,7 @@ namespace Drupal\layout_builder_enhancements_views\Plugin\views\display; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Markup; use Drupal\views\Plugin\views\display\Embed; @@ -27,6 +28,7 @@ class Inline extends Embed { /** * {@inheritdoc} */ + #[\Override] protected function defineOptions() { $options = parent::defineOptions(); $options['category'] = [ @@ -48,6 +50,7 @@ class Inline extends Embed { /** * {@inheritdoc} */ + #[\Override] public function optionsSummary(&$categories, &$options) { parent::optionsSummary($categories, $options); @@ -74,7 +77,7 @@ class Inline extends Embed { $options['category'] = [ 'category' => 'category', 'title' => $this->t('Category'), - 'value' => views_ui_truncate($str, 24), + 'value' => Unicode::truncate($str, 24), ]; $options['icon'] = [ @@ -87,6 +90,7 @@ class Inline extends Embed { /** * {@inheritdoc} */ + #[\Override] public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); @@ -129,6 +133,7 @@ class Inline extends Embed { /** * {@inheritdoc} */ + #[\Override] public function submitOptionsForm(&$form, FormStateInterface $form_state) { parent::submitOptionsForm($form, $form_state); diff --git a/modules/layout_builder_enhancements_visual/layout_builder_enhancements_visual.info.yml b/modules/layout_builder_enhancements_visual/layout_builder_enhancements_visual.info.yml index 9707c6fa9688ae9224a290e549a4de3232ce67ce..9f0f0a4c459d21d9594d6e91946d4d21c23586b0 100644 --- a/modules/layout_builder_enhancements_visual/layout_builder_enhancements_visual.info.yml +++ b/modules/layout_builder_enhancements_visual/layout_builder_enhancements_visual.info.yml @@ -1,7 +1,7 @@ -name: 'Layout Builder Enhancements' +name: 'Layout Builder Enhancements - Visual' type: module description: 'Add some functionality for layout builder.' -core_version_requirement: ^8 || ^9 || ^10 +core_version_requirement: ^9 || ^10 || ^11 package: 'Layout' dependencies: - layout_builder_enhancements:layout_builder_enhancements diff --git a/modules/layout_builder_enhancements_visual/src/Ajax/ShowInfoCommand.php b/modules/layout_builder_enhancements_visual/src/Ajax/ShowInfoCommand.php index 1fd03cafdd81b847d222530d1aa2abab620a04fb..8182ceaccba9feda5bcd4c06cc76da3dd00024ea 100644 --- a/modules/layout_builder_enhancements_visual/src/Ajax/ShowInfoCommand.php +++ b/modules/layout_builder_enhancements_visual/src/Ajax/ShowInfoCommand.php @@ -9,6 +9,7 @@ use Drupal\Core\Ajax\CommandInterface; */ class ShowInfoCommand implements CommandInterface { + #[\Override] public function render() { return [ 'command' => 'ShowInfoCommand', diff --git a/modules/layout_builder_enhancements_visual/src/Controller/InfoController.php b/modules/layout_builder_enhancements_visual/src/Controller/InfoController.php index e4dfcc8e083a0f18e699d67dea74ed1682004bf1..318fd8bb8f645d41ced4a2ea3f71ad1edd796591 100644 --- a/modules/layout_builder_enhancements_visual/src/Controller/InfoController.php +++ b/modules/layout_builder_enhancements_visual/src/Controller/InfoController.php @@ -13,6 +13,7 @@ use Drupal\Core\Ajax\CommandInterface; */ class ShowInfoCommand implements CommandInterface { + #[\Override] public function render() { return [ 'command' => 'ShowInfoCommand', diff --git a/src/EventSubscriber/EventSubscriber.php b/src/EventSubscriber/EventSubscriber.php index f9c51d379a20a0ad61d329a5ea9dd3fbf8dfa8c9..55f7a2f5be11ca1a3527763458698362bdfba1d5 100644 --- a/src/EventSubscriber/EventSubscriber.php +++ b/src/EventSubscriber/EventSubscriber.php @@ -29,7 +29,8 @@ class EventSubscriber implements EventSubscriberInterface { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + #[\Override] + public static function getSubscribedEvents(): array { return [ LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY => [ 'onBuildRender', diff --git a/tests/modules/layout_builder_enhancements_test/config/install/core.entity_view_display.node.landingpage.default.yml b/tests/modules/layout_builder_enhancements_test/config/install/core.entity_view_display.node.landingpage.default.yml new file mode 100644 index 0000000000000000000000000000000000000000..7381eaf1c0df34db1c1b9ee60088007b598f159c --- /dev/null +++ b/tests/modules/layout_builder_enhancements_test/config/install/core.entity_view_display.node.landingpage.default.yml @@ -0,0 +1,26 @@ +langcode: en +status: true +dependencies: + config: + - node.type.landingpage + module: + - layout_builder + - layout_builder_enhancements_views + - text + - user +third_party_settings: + layout_builder: + enabled: true + allow_custom: false + sections: {} +id: node.landingpage.default +targetEntityType: node +bundle: landingpage +mode: default +content: + links: + settings: { } + third_party_settings: { } + weight: 100 + region: content +hidden: { } diff --git a/tests/modules/layout_builder_enhancements_test/config/install/node.type.article.yml b/tests/modules/layout_builder_enhancements_test/config/install/node.type.article.yml new file mode 100644 index 0000000000000000000000000000000000000000..5b5098a22f4e1cbe5c047b13fab015252b9850db --- /dev/null +++ b/tests/modules/layout_builder_enhancements_test/config/install/node.type.article.yml @@ -0,0 +1,11 @@ +langcode: en +status: true +dependencies: {} +third_party_settings: {} +name: Article +type: article +description: 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.' +help: null +new_revision: true +preview_mode: 1 +display_submitted: true diff --git a/tests/modules/layout_builder_enhancements_test/config/install/node.type.landingpage.yml b/tests/modules/layout_builder_enhancements_test/config/install/node.type.landingpage.yml new file mode 100644 index 0000000000000000000000000000000000000000..6ee84b5d33b778db0898d96a661005e8d55bd83b --- /dev/null +++ b/tests/modules/layout_builder_enhancements_test/config/install/node.type.landingpage.yml @@ -0,0 +1,11 @@ +langcode: en +status: true +dependencies: {} +third_party_settings: {} +name: Landingpage +type: landingpage +description: null +help: null +new_revision: true +preview_mode: 1 +display_submitted: true diff --git a/tests/modules/layout_builder_enhancements_test/config/install/views.view.articles.yml b/tests/modules/layout_builder_enhancements_test/config/install/views.view.articles.yml new file mode 100644 index 0000000000000000000000000000000000000000..5457b507d4c8edc355869a3178e02fd2d2ae0428 --- /dev/null +++ b/tests/modules/layout_builder_enhancements_test/config/install/views.view.articles.yml @@ -0,0 +1,230 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.node.teaser + - node.type.article + module: + - layout_builder_enhancements_views + - node + - user +id: articles +label: Articles +module: views +description: '' +tag: '' +base_table: node_field_data +base_field: nid +display: + default: + id: default + display_title: Default + display_plugin: default + position: 0 + display_options: + fields: + title: + id: title + table: node_field_data + field: title + relationship: none + group_type: group + admin_label: '' + entity_type: node + entity_field: title + plugin_id: field + label: '' + exclude: false + alter: + alter_text: false + make_link: false + absolute: false + word_boundary: false + ellipsis: false + strip_tags: false + trim: false + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + pager: + type: mini + options: + offset: 0 + pagination_heading_level: h4 + items_per_page: 10 + total_pages: null + id: 0 + tags: + next: ›› + previous: ‹‹ + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + access: + type: perm + options: + perm: 'access content' + cache: + type: tag + options: { } + empty: { } + sorts: + created: + id: created + table: node_field_data + field: created + relationship: none + group_type: group + admin_label: '' + entity_type: node + entity_field: created + plugin_id: date + order: ASC + expose: + label: '' + field_identifier: '' + exposed: false + granularity: second + arguments: { } + filters: + status: + id: status + table: node_field_data + field: status + entity_type: node + entity_field: status + plugin_id: boolean + value: '1' + group: 1 + expose: + operator: '' + type: + id: type + table: node_field_data + field: type + relationship: none + group_type: group + admin_label: '' + entity_type: node + entity_field: type + plugin_id: bundle + operator: in + value: + article: article + group: 1 + exposed: false + expose: + operator_id: '' + label: '' + description: '' + use_operator: false + operator: '' + operator_limit_selection: false + operator_list: { } + identifier: '' + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + reduce: false + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + style: + type: default + options: + grouping: { } + row_class: '' + default_row_class: true + uses_fields: false + row: + type: 'entity:node' + options: + relationship: none + view_mode: teaser + query: + type: views_query + options: + query_comment: '' + disable_sql_rewrite: false + distinct: false + replica: false + query_tags: { } + relationships: { } + header: { } + footer: { } + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } + inline_1: + id: inline_1 + display_title: Inline + display_plugin: inline + position: 1 + display_options: + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } diff --git a/tests/modules/layout_builder_enhancements_test/layout_builder_enhancements_test.info.yml b/tests/modules/layout_builder_enhancements_test/layout_builder_enhancements_test.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..635df5011d91ad8f9a17c46904b40d1cec966738 --- /dev/null +++ b/tests/modules/layout_builder_enhancements_test/layout_builder_enhancements_test.info.yml @@ -0,0 +1,14 @@ +name: 'Layout Builder Enhancements Views Test' +description: 'Support module for testing purposes.' +package: 'Testing' +type: 'module' +core_version_requirement: ^9 || ^10 || ^11 +dependencies: + - 'drupal:user' + - 'drupal:field_ui' + - 'drupal:text' + - 'drupal:block' + - 'drupal:node' + - 'drupal:layout_builder' + - 'drupal:layout_builder_enhancements' + - 'drupal:layout_builder_enhancements_views' diff --git a/tests/src/Functional/LayoutBuilderEnhancementsViewsTest.php b/tests/src/Functional/LayoutBuilderEnhancementsViewsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8105b540871058fafc8b5b8212ab33176ac6dea5 --- /dev/null +++ b/tests/src/Functional/LayoutBuilderEnhancementsViewsTest.php @@ -0,0 +1,151 @@ +<?php + +namespace Drupal\Tests\layout_builder_enhancements\Functional; + +use Drupal\Tests\BrowserTestBase; +use Drupal\Core\StringTranslation\StringTranslationTrait; + +/** + * Functional tests for the layout_builder_enhancements views feature. + * + * @group layout_builder_enhancements + */ +class LayoutBuilderEnhancementsViewsTest extends BrowserTestBase { + + use StringTranslationTrait; + + /** + * {@inheritdoc} + */ + protected static $configSchemaCheckerExclusions = [ + // Currently no proper schema configured. Be less strict for the time + // being and fix it at a later stage. + // + // Tightly connected to + // https://www.drupal.org/project/drupal/issues/3015152 + 'core.entity_view_display.node.landingpage.default', + ]; + + /** + * Modules to enable. + * + * @var array + */ + protected static $modules = [ + 'layout_builder_enhancements_test', + ]; + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + + /** + * The list of created nodes during testing. + * + * @var \Drupal\node\NodeInterface[] + */ + protected $nodes; + + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + $this->nodes[] = $this->createNode([ + 'type' => 'landingpage', + 'title' => 'Frontpage', + ]); + + $this->nodes[] = $this->createNode([ + 'type' => 'article', + 'title' => 'Article 1', + ]); + $this->nodes[] = $this->createNode([ + 'type' => 'article', + 'title' => 'Article 2', + ]); + $this->nodes[] = $this->createNode([ + 'type' => 'article', + 'title' => 'Article 3', + ]); + $this->nodes[] = $this->createNode([ + 'type' => 'article', + 'title' => 'Article 4', + ]); + $this->nodes[] = $this->createNode([ + 'type' => 'article', + 'title' => 'Article 5', + ]); + } + + /** + * Make sure the LBE Views blocks are respecting the pager settings. + * + * @return void + */ + public function testAddViewsBlock() { + $this->drupalLogin($this->rootUser); + $this->drupalGet('admin/structure/types/manage/landingpage/display/default/layout'); + $this->clickLink('Add section'); + $this->clickLink('Three column'); + $this->getSession()->getPage()->pressButton('Add section'); + + // Create first block. + $this->clickLink('Add block in Section 1, First region'); + $this->clickLink('Articles: Inline'); + $this->getSession()->getPage()->checkField('Should respect pager'); + $this->getSession()->getPage()->selectFieldOption('View mode', 'teaser'); + $this->getSession()->getPage()->pressButton('Add block'); + + // Create second block. + $this->clickLink('Add block in Section 1, Second region'); + $this->clickLink('Articles: Inline'); + $this->getSession()->getPage()->checkField('Should respect pager'); + $this->getSession()->getPage()->selectFieldOption('View mode', 'teaser'); + $this->getSession()->getPage()->pressButton('Add block'); + + // Create second block. + $this->clickLink('Add block in Section 1, Third region'); + $this->clickLink('Articles: Inline'); + $this->getSession()->getPage()->checkField('Should respect pager'); + $this->getSession()->getPage()->selectFieldOption('View mode', 'teaser'); + $this->getSession()->getPage()->pressButton('Add block'); + + // Save the layout. + $this->getSession()->getPage()->pressButton('Save layout'); + + // Visit the landingpage and check the layout. + $this->drupalGet('node/1'); + $this->assertSession()->linkExists('Article 1'); + $this->assertSession()->linkExists('Article 2'); + $this->assertSession()->linkExists('Article 3'); + $this->assertSession()->linkNotExists('Article 4'); + $this->assertSession()->linkNotExists('Article 5'); + + // Configure the a new section + block to show all remaining items. + $this->drupalGet('admin/structure/types/manage/landingpage/display/default/layout'); + $this->clickLink('Add section at end of layout'); + $this->clickLink('One column'); + $this->getSession()->getPage()->pressButton('Add section'); + $this->clickLink('Add block in Section 2, Content region'); + $this->clickLink('Articles: Inline'); + $this->getSession()->getPage()->checkField('Should respect pager'); + $this->getSession()->getPage()->checkField('Show all remaining rows'); + $this->getSession()->getPage()->selectFieldOption('View mode', 'teaser'); + $this->getSession()->getPage()->pressButton('Add block'); + $this->getSession()->getPage()->pressButton('Save'); + + // Visit the landingpage and check that article 4 and 5 are shown, so all + // remaining items. + $this->drupalGet('node/1'); + $this->assertSession()->linkExists('Article 1'); + $this->assertSession()->linkExists('Article 2'); + $this->assertSession()->linkExists('Article 3'); + $this->assertSession()->linkExists('Article 4'); + $this->assertSession()->linkExists('Article 5'); + + } + +}