Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
< ? php
/**
* @ file
* Provides hook implementations for Layout Builder .
*/
2019-02-13 19:51:49 +00:00
use Drupal\Core\Breadcrumb\Breadcrumb ;
use Drupal\Core\Cache\CacheableMetadata ;
Issue #2957425 by tedbow, johndevman, mpotter, tim.plunkett, hawkeye.twolf, alexpott, Berdir, samuel.mortenson, xjm, kevincrafts, jibran, amateescu, larowlan, twfahey, EclipseGc, sjerdo, japerry, mtodor, phenaproxima, johnzzon, mglaman: Allow the inline creation of non-reusable Custom Blocks in the layout builder
2018-08-25 17:07:16 +00:00
use Drupal\Core\Entity\EntityInterface ;
2019-02-13 04:09:13 +00:00
use Drupal\Core\Entity\FieldableEntityInterface ;
Issue #2921810 by claudiu.cristea, nod_, seanB, yogeshmpawar, dww, Wilfred Waltman, joelpittet, askibinski, ankithashetty, ravi.shankar, jonathanshaw, alexpott, kostyashupenko, webchick, danflanagan8, catch, droplet, larowlan, mpdonadio, jhedstrom, AaronMcHale, dawehner, Wim Leers, ckrina, worldlinemine: Allow TimestampFormatter to show as a fully cacheable time difference with JS
2023-03-03 16:35:58 +00:00
use Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampFormatter ;
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
use Drupal\Core\Form\FormStateInterface ;
2019-02-13 19:51:49 +00:00
use Drupal\Core\Link ;
2019-01-09 21:24:56 +00:00
use Drupal\Core\Render\Element ;
2018-01-15 21:13:53 +00:00
use Drupal\Core\Routing\RouteMatchInterface ;
use Drupal\Core\Url ;
2018-01-30 22:28:03 +00:00
use Drupal\field\FieldConfigInterface ;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay ;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage ;
Issue #2921810 by claudiu.cristea, nod_, seanB, yogeshmpawar, dww, Wilfred Waltman, joelpittet, askibinski, ankithashetty, ravi.shankar, jonathanshaw, alexpott, kostyashupenko, webchick, danflanagan8, catch, droplet, larowlan, mpdonadio, jhedstrom, AaronMcHale, dawehner, Wim Leers, ckrina, worldlinemine: Allow TimestampFormatter to show as a fully cacheable time difference with JS
2023-03-03 16:35:58 +00:00
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface ;
2019-02-13 04:09:13 +00:00
use Drupal\layout_builder\Form\DefaultsEntityForm ;
2018-01-30 22:28:03 +00:00
use Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm ;
2019-02-13 04:09:13 +00:00
use Drupal\layout_builder\Form\OverridesEntityForm ;
2018-07-23 09:11:33 +00:00
use Drupal\Core\Entity\Display\EntityViewDisplayInterface ;
use Drupal\layout_builder\Plugin\Block\ExtraFieldBlock ;
Issue #2957425 by tedbow, johndevman, mpotter, tim.plunkett, hawkeye.twolf, alexpott, Berdir, samuel.mortenson, xjm, kevincrafts, jibran, amateescu, larowlan, twfahey, EclipseGc, sjerdo, japerry, mtodor, phenaproxima, johnzzon, mglaman: Allow the inline creation of non-reusable Custom Blocks in the layout builder
2018-08-25 17:07:16 +00:00
use Drupal\layout_builder\InlineBlockEntityOperations ;
use Drupal\Core\Session\AccountInterface ;
use Drupal\Core\Access\AccessResult ;
2018-11-22 11:59:49 +00:00
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage ;
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
/**
* Implements hook_help () .
*/
2018-01-15 21:13:53 +00:00
function layout_builder_help ( $route_name , RouteMatchInterface $route_match ) {
// Add help text to the Layout Builder UI.
if ( $route_match -> getRouteObject () -> getOption ( '_layout_builder' )) {
$output = '<p>' . t ( 'This layout builder tool allows you to configure the layout of the main content area.' ) . '</p>' ;
if ( \Drupal :: currentUser () -> hasPermission ( 'administer blocks' )) {
$output .= '<p>' . t ( 'To manage other areas of the page, use the <a href="@block-ui">block administration page</a>.' , [ '@block-ui' => Url :: fromRoute ( 'block.admin_display' ) -> toString ()]) . '</p>' ;
}
else {
$output .= '<p>' . t ( 'To manage other areas of the page, use the block administration page.' ) . '</p>' ;
}
2019-02-21 17:22:25 +00:00
$output .= '<p>' . t ( 'Forms and links inside the content of the layout builder tool have been disabled.' ) . '</p>' ;
2018-01-15 21:13:53 +00:00
return $output ;
}
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
switch ( $route_name ) {
case 'help.page.layout_builder' :
2024-01-15 12:55:37 +00:00
$output = '<h2>' . t ( 'About' ) . '</h2>' ;
2023-04-17 08:50:08 +00:00
$output .= '<p>' . t ( 'Layout Builder allows you to use layouts to customize how content, content blocks, and other <a href=":field_help" title="Field module help, with background on content entities">content entities</a> are displayed.' , [ ':field_help' => Url :: fromRoute ( 'help.page' , [ 'name' => 'field' ]) -> toString ()]) . '</p>' ;
2019-03-05 21:05:44 +00:00
$output .= '<p>' . t ( 'For more information, see the <a href=":layout-builder-documentation">online documentation for the Layout Builder module</a>.' , [ ':layout-builder-documentation' => 'https://www.drupal.org/docs/8/core/modules/layout-builder' ]) . '</p>' ;
2024-01-15 12:55:37 +00:00
$output .= '<h2>' . t ( 'Uses' ) . '</h2>' ;
2019-03-05 21:05:44 +00:00
$output .= '<dl>' ;
$output .= '<dt>' . t ( 'Default layouts' ) . '</dt>' ;
$output .= '<dd>' . t ( 'Layout Builder can be selectively enabled on the "Manage Display" page in the <a href=":field_ui">Field UI</a>. This allows you to control the output of each type of display individually. For example, a "Basic page" might have view modes such as Full and Teaser, with each view mode having different layouts selected.' , [ ':field_ui' => Url :: fromRoute ( 'help.page' , [ 'name' => 'field_ui' ]) -> toString ()]) . '</dd>' ;
$output .= '<dt>' . t ( 'Overridden layouts' ) . '</dt>' ;
$output .= '<dd>' . t ( 'If enabled, each individual content item can have a custom layout. Once the layout for an individual content item is overridden, changes to the Default layout will no longer affect it. Overridden layouts may be reverted to return to matching and being synchronized to their Default layout.' ) . '</dd>' ;
Issue #2914486 by tim.plunkett, tedbow, bendeguz.csirmaz, twfahey, bnjmnm, xjm, effulgentsia, Kristen Pol, benjifisher, larowlan, webchick, rainbreaw, jrockowitz, Gábor Hojtsy, ckrina: Add granular permissions to the Layout Builder
(cherry picked from commit d05d67fede00690e22fe557dcb6fee5752a3e8d5)
2019-03-26 05:55:38 +00:00
$output .= '<dt>' . t ( 'User permissions' ) . '</dt>' ;
$output .= '<dd>' . t ( 'The Layout Builder module makes a number of permissions available, which can be set by role on the <a href=":permissions">permissions page</a>. For more information, see the <a href=":layout-builder-permissions">Configuring Layout Builder permissions</a> online documentation.' , [
2021-10-18 12:08:44 +00:00
':permissions' => Url :: fromRoute ( 'user.admin_permissions.module' , [ 'modules' => 'layout_builder' ]) -> toString (),
Issue #2914486 by tim.plunkett, tedbow, bendeguz.csirmaz, twfahey, bnjmnm, xjm, effulgentsia, Kristen Pol, benjifisher, larowlan, webchick, rainbreaw, jrockowitz, Gábor Hojtsy, ckrina: Add granular permissions to the Layout Builder
(cherry picked from commit d05d67fede00690e22fe557dcb6fee5752a3e8d5)
2019-03-26 05:55:38 +00:00
':layout-builder-permissions' => 'https://www.drupal.org/docs/8/core/modules/layout-builder/configuring-layout-builder-permissions' ,
]) . '</dd>' ;
2019-03-05 21:05:44 +00:00
$output .= '</dl>' ;
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
return $output ;
}
}
/**
* Implements hook_entity_type_alter () .
*/
function layout_builder_entity_type_alter ( array & $entity_types ) {
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
2018-01-30 22:28:03 +00:00
$entity_types [ 'entity_view_display' ]
-> setClass ( LayoutBuilderEntityViewDisplay :: class )
-> setStorageClass ( LayoutBuilderEntityViewDisplayStorage :: class )
2019-02-13 04:09:13 +00:00
-> setFormClass ( 'layout_builder' , DefaultsEntityForm :: class )
2018-01-30 22:28:03 +00:00
-> setFormClass ( 'edit' , LayoutBuilderEntityViewDisplayForm :: class );
2019-02-13 04:09:13 +00:00
// Ensure every fieldable entity type has a layout form.
foreach ( $entity_types as $entity_type ) {
if ( $entity_type -> entityClassImplements ( FieldableEntityInterface :: class )) {
$entity_type -> setFormClass ( 'layout_builder' , OverridesEntityForm :: class );
}
}
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
}
/**
2018-01-30 22:28:03 +00:00
* Implements hook_form_FORM_ID_alter () for \Drupal\field_ui\Form\EntityFormDisplayEditForm .
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
*/
2018-01-30 22:28:03 +00:00
function layout_builder_form_entity_form_display_edit_form_alter ( & $form , FormStateInterface $form_state ) {
// Hides the Layout Builder field. It is rendered directly in
// \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildMultiple().
2018-11-22 11:59:49 +00:00
unset ( $form [ 'fields' ][ OverridesSectionStorage :: FIELD_NAME ]);
$key = array_search ( OverridesSectionStorage :: FIELD_NAME , $form [ '#fields' ]);
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
if ( $key !== FALSE ) {
unset ( $form [ '#fields' ][ $key ]);
}
}
/**
2018-01-30 22:28:03 +00:00
* Implements hook_field_config_insert () .
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
*/
2018-01-30 22:28:03 +00:00
function layout_builder_field_config_insert ( FieldConfigInterface $field_config ) {
// Clear the sample entity for this entity type and bundle.
2018-02-05 03:19:43 +00:00
$sample_entity_generator = \Drupal :: service ( 'layout_builder.sample_entity_generator' );
$sample_entity_generator -> delete ( $field_config -> getTargetEntityTypeId (), $field_config -> getTargetBundle ());
2018-01-30 22:28:03 +00:00
\Drupal :: service ( 'plugin.manager.block' ) -> clearCachedDefinitions ();
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
}
/**
2018-01-30 22:28:03 +00:00
* Implements hook_field_config_delete () .
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
*/
2018-01-30 22:28:03 +00:00
function layout_builder_field_config_delete ( FieldConfigInterface $field_config ) {
// Clear the sample entity for this entity type and bundle.
2018-02-05 03:19:43 +00:00
$sample_entity_generator = \Drupal :: service ( 'layout_builder.sample_entity_generator' );
$sample_entity_generator -> delete ( $field_config -> getTargetEntityTypeId (), $field_config -> getTargetBundle ());
2018-01-30 22:28:03 +00:00
\Drupal :: service ( 'plugin.manager.block' ) -> clearCachedDefinitions ();
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
}
2018-07-23 09:11:33 +00:00
/**
* Implements hook_entity_view_alter () .
*
* ExtraFieldBlock block plugins add placeholders for each extra field which is
* configured to be displayed . Those placeholders are replaced by this hook .
* Modules that implement hook_entity_extra_field_info () use their
* implementations of hook_entity_view_alter () to add the rendered output of
* the extra fields they provide , so we cannot get the rendered output of extra
* fields before this point in the view process .
* layout_builder_module_implements_alter () moves this implementation of
* hook_entity_view_alter () to the end of the list .
*
* @ see \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock :: build ()
* @ see layout_builder_module_implements_alter ()
*/
function layout_builder_entity_view_alter ( array & $build , EntityInterface $entity , EntityViewDisplayInterface $display ) {
2019-01-09 21:24:56 +00:00
// Only replace extra fields when Layout Builder has been used to alter the
// build. See \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildMultiple().
if ( isset ( $build [ '_layout_builder' ]) && ! Element :: isEmpty ( $build [ '_layout_builder' ])) {
2018-07-23 09:11:33 +00:00
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
$field_manager = \Drupal :: service ( 'entity_field.manager' );
$extra_fields = $field_manager -> getExtraFields ( $entity -> getEntityTypeId (), $entity -> bundle ());
if ( ! empty ( $extra_fields [ 'display' ])) {
foreach ( $extra_fields [ 'display' ] as $field_name => $extra_field ) {
// If the extra field is not set replace with an empty array to avoid
// the placeholder text from being rendered.
2021-11-15 02:19:43 +00:00
$replacement = $build [ $field_name ] ? ? [];
2018-07-23 09:11:33 +00:00
ExtraFieldBlock :: replaceFieldPlaceholder ( $build , $replacement , $field_name );
// After the rendered field in $build has been copied over to the
// ExtraFieldBlock block we must remove it from its original location or
// else it will be rendered twice.
unset ( $build [ $field_name ]);
}
}
}
2019-03-21 16:31:53 +00:00
$route_name = \Drupal :: routeMatch () -> getRouteName ();
// If the entity is displayed within a Layout Builder block and the current
// route is in the Layout Builder UI, then remove all contextual link
// placeholders.
2023-02-13 21:10:45 +00:00
if ( $route_name && $display instanceof LayoutBuilderEntityViewDisplay && str_starts_with ( $route_name , 'layout_builder.' )) {
2019-03-21 16:31:53 +00:00
unset ( $build [ '#contextual_links' ]);
}
}
/**
* Implements hook_entity_build_defaults_alter () .
*/
function layout_builder_entity_build_defaults_alter ( array & $build , EntityInterface $entity , $view_mode ) {
// Contextual links are removed for entities viewed in Layout Builder's UI.
// The route.name.is_layout_builder_ui cache context accounts for this
// difference.
// @see layout_builder_entity_view_alter()
// @see \Drupal\layout_builder\Cache\LayoutBuilderUiCacheContext
$build [ '#cache' ][ 'contexts' ][] = 'route.name.is_layout_builder_ui' ;
2018-07-23 09:11:33 +00:00
}
/**
2019-07-11 14:38:23 +00:00
* Implements hook_module_implements_alter () .
2018-07-23 09:11:33 +00:00
*/
function layout_builder_module_implements_alter ( & $implementations , $hook ) {
if ( $hook === 'entity_view_alter' ) {
// Ensure that this module's implementation of hook_entity_view_alter() runs
// last so that other modules that use this hook to render extra fields will
// run before it.
$group = $implementations [ 'layout_builder' ];
unset ( $implementations [ 'layout_builder' ]);
$implementations [ 'layout_builder' ] = $group ;
}
}
Issue #2957425 by tedbow, johndevman, mpotter, tim.plunkett, hawkeye.twolf, alexpott, Berdir, samuel.mortenson, xjm, kevincrafts, jibran, amateescu, larowlan, twfahey, EclipseGc, sjerdo, japerry, mtodor, phenaproxima, johnzzon, mglaman: Allow the inline creation of non-reusable Custom Blocks in the layout builder
2018-08-25 17:07:16 +00:00
/**
* Implements hook_entity_presave () .
*/
function layout_builder_entity_presave ( EntityInterface $entity ) {
if ( \Drupal :: moduleHandler () -> moduleExists ( 'block_content' )) {
/** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */
$entity_operations = \Drupal :: classResolver ( InlineBlockEntityOperations :: class );
$entity_operations -> handlePreSave ( $entity );
}
}
/**
* Implements hook_entity_delete () .
*/
function layout_builder_entity_delete ( EntityInterface $entity ) {
if ( \Drupal :: moduleHandler () -> moduleExists ( 'block_content' )) {
/** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */
$entity_operations = \Drupal :: classResolver ( InlineBlockEntityOperations :: class );
$entity_operations -> handleEntityDelete ( $entity );
}
}
/**
* Implements hook_cron () .
*/
function layout_builder_cron () {
if ( \Drupal :: moduleHandler () -> moduleExists ( 'block_content' )) {
/** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */
$entity_operations = \Drupal :: classResolver ( InlineBlockEntityOperations :: class );
$entity_operations -> removeUnused ();
}
}
2019-01-31 22:29:57 +00:00
/**
* Implements hook_plugin_filter_TYPE__CONSUMER_alter () .
*/
function layout_builder_plugin_filter_block__layout_builder_alter ( array & $definitions , array $extra ) {
2023-06-09 19:44:26 +00:00
// Remove blocks that are not useful within Layout Builder.
unset ( $definitions [ 'system_messages_block' ]);
unset ( $definitions [ 'help_block' ]);
unset ( $definitions [ 'local_tasks_block' ]);
unset ( $definitions [ 'local_actions_block' ]);
// Remove blocks that are non-functional within Layout Builder.
2021-07-03 00:43:16 +00:00
unset ( $definitions [ 'system_main_block' ]);
2019-01-31 22:29:57 +00:00
// @todo Restore the page title block in https://www.drupal.org/node/2938129.
unset ( $definitions [ 'page_title_block' ]);
}
Issue #2957425 by tedbow, johndevman, mpotter, tim.plunkett, hawkeye.twolf, alexpott, Berdir, samuel.mortenson, xjm, kevincrafts, jibran, amateescu, larowlan, twfahey, EclipseGc, sjerdo, japerry, mtodor, phenaproxima, johnzzon, mglaman: Allow the inline creation of non-reusable Custom Blocks in the layout builder
2018-08-25 17:07:16 +00:00
/**
* Implements hook_plugin_filter_TYPE_alter () .
*/
function layout_builder_plugin_filter_block_alter ( array & $definitions , array $extra , $consumer ) {
// @todo Determine the 'inline_block' blocks should be allowed outside
// of layout_builder https://www.drupal.org/node/2979142.
2018-11-12 20:45:33 +00:00
if ( $consumer !== 'layout_builder' || ! isset ( $extra [ 'list' ]) || $extra [ 'list' ] !== 'inline_blocks' ) {
Issue #2957425 by tedbow, johndevman, mpotter, tim.plunkett, hawkeye.twolf, alexpott, Berdir, samuel.mortenson, xjm, kevincrafts, jibran, amateescu, larowlan, twfahey, EclipseGc, sjerdo, japerry, mtodor, phenaproxima, johnzzon, mglaman: Allow the inline creation of non-reusable Custom Blocks in the layout builder
2018-08-25 17:07:16 +00:00
foreach ( $definitions as $id => $definition ) {
if ( $definition [ 'id' ] === 'inline_block' ) {
unset ( $definitions [ $id ]);
}
}
}
}
/**
* Implements hook_ENTITY_TYPE_access () .
*/
function layout_builder_block_content_access ( EntityInterface $entity , $operation , AccountInterface $account ) {
/** @var \Drupal\block_content\BlockContentInterface $entity */
if ( $operation === 'view' || $entity -> isReusable () || empty ( \Drupal :: service ( 'inline_block.usage' ) -> getUsage ( $entity -> id ()))) {
// If the operation is 'view' or this is reusable block or if this is
// non-reusable that isn't used by this module then don't alter the access.
return AccessResult :: neutral ();
}
Issue #2914486 by tim.plunkett, tedbow, bendeguz.csirmaz, twfahey, bnjmnm, xjm, effulgentsia, Kristen Pol, benjifisher, larowlan, webchick, rainbreaw, jrockowitz, Gábor Hojtsy, ckrina: Add granular permissions to the Layout Builder
(cherry picked from commit d05d67fede00690e22fe557dcb6fee5752a3e8d5)
2019-03-26 05:55:38 +00:00
if ( $account -> hasPermission ( 'create and edit custom blocks' )) {
Issue #2957425 by tedbow, johndevman, mpotter, tim.plunkett, hawkeye.twolf, alexpott, Berdir, samuel.mortenson, xjm, kevincrafts, jibran, amateescu, larowlan, twfahey, EclipseGc, sjerdo, japerry, mtodor, phenaproxima, johnzzon, mglaman: Allow the inline creation of non-reusable Custom Blocks in the layout builder
2018-08-25 17:07:16 +00:00
return AccessResult :: allowed ();
}
return AccessResult :: forbidden ();
}
2018-11-28 11:59:59 +00:00
/**
* Implements hook_plugin_filter_TYPE__CONSUMER_alter () .
*/
function layout_builder_plugin_filter_block__block_ui_alter ( array & $definitions , array $extra ) {
foreach ( $definitions as $id => $definition ) {
2019-01-13 21:47:56 +00:00
// Filter out any layout_builder-provided block that has required context
// definitions.
if ( $definition [ 'provider' ] === 'layout_builder' && ! empty ( $definition [ 'context_definitions' ])) {
/** @var \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context_definition */
foreach ( $definition [ 'context_definitions' ] as $context_definition ) {
if ( $context_definition -> isRequired ()) {
2018-11-28 11:59:59 +00:00
unset ( $definitions [ $id ]);
break ;
}
}
}
}
}
2018-12-10 22:18:57 +00:00
2019-01-07 22:00:47 +00:00
/**
* Implements hook_plugin_filter_TYPE__CONSUMER_alter () .
*/
function layout_builder_plugin_filter_layout__layout_builder_alter ( array & $definitions , array $extra ) {
// Remove layouts provide by layout discovery that are not needed because of
// layouts provided by this module.
$duplicate_layouts = [
'layout_twocol' ,
'layout_twocol_bricks' ,
'layout_threecol_25_50_25' ,
'layout_threecol_33_34_33' ,
];
foreach ( $duplicate_layouts as $duplicate_layout ) {
/** @var \Drupal\Core\Layout\LayoutDefinition[] $definitions */
if ( isset ( $definitions [ $duplicate_layout ])) {
if ( $definitions [ $duplicate_layout ] -> getProvider () === 'layout_discovery' ) {
unset ( $definitions [ $duplicate_layout ]);
}
}
}
// Move the one column layout to the top.
if ( isset ( $definitions [ 'layout_onecol' ]) && $definitions [ 'layout_onecol' ] -> getProvider () === 'layout_discovery' ) {
$one_col = $definitions [ 'layout_onecol' ];
unset ( $definitions [ 'layout_onecol' ]);
$definitions = [
'layout_onecol' => $one_col ,
] + $definitions ;
}
}
2019-02-13 19:51:49 +00:00
2019-03-01 03:39:47 +00:00
/**
* Implements hook_plugin_filter_TYPE_alter () .
*/
function layout_builder_plugin_filter_layout_alter ( array & $definitions , array $extra , $consumer ) {
// Hide the blank layout plugin from listings.
unset ( $definitions [ 'layout_builder_blank' ]);
}
2019-02-13 19:51:49 +00:00
/**
* Implements hook_system_breadcrumb_alter () .
*/
function layout_builder_system_breadcrumb_alter ( Breadcrumb & $breadcrumb , RouteMatchInterface $route_match , array $context ) {
// Remove the extra 'Manage display' breadcrumb for Layout Builder defaults.
2021-09-09 00:00:01 +00:00
if ( $route_match -> getRouteObject () && $route_match -> getRouteObject () -> hasOption ( '_layout_builder' ) && $route_match -> getParameter ( 'section_storage_type' ) === 'defaults' ) {
2019-02-13 19:51:49 +00:00
$links = array_filter ( $breadcrumb -> getLinks (), function ( Link $link ) use ( $route_match ) {
$entity_type_id = $route_match -> getParameter ( 'entity_type_id' );
2021-03-25 20:06:05 +00:00
if ( ! $link -> getUrl () -> isRouted ()) {
return TRUE ;
}
2019-02-13 19:51:49 +00:00
return $link -> getUrl () -> getRouteName () !== " entity.entity_view_display. $entity_type_id .default " ;
});
// Links cannot be removed from an existing breadcrumb object. Create a new
// object but carry over the cacheable metadata.
$cacheability = CacheableMetadata :: createFromObject ( $breadcrumb );
$breadcrumb = new Breadcrumb ();
$breadcrumb -> setLinks ( $links );
$breadcrumb -> addCacheableDependency ( $cacheability );
}
}
Issue #2948828 by tedbow, Wim Leers, tim.plunkett, samuel.mortenson, johndevman, Kristen Pol, webchick, phenaproxima, larowlan, dead_arm, bnjmnm: Layout Builder's Field Blocks do not work with Quick Edit
2019-03-25 20:05:29 +00:00
2019-03-27 04:47:30 +00:00
/**
* Implements hook_entity_translation_create () .
*/
function layout_builder_entity_translation_create ( EntityInterface $translation ) {
/** @var \Drupal\Core\Entity\FieldableEntityInterface $translation */
if ( $translation -> hasField ( OverridesSectionStorage :: FIELD_NAME ) && $translation -> getFieldDefinition ( OverridesSectionStorage :: FIELD_NAME ) -> isTranslatable ()) {
// When creating a new translation do not copy untranslated sections because
// per-language layouts are not supported.
$translation -> set ( OverridesSectionStorage :: FIELD_NAME , []);
}
}
2019-03-28 06:39:30 +00:00
/**
* Implements hook_theme_registry_alter () .
*/
function layout_builder_theme_registry_alter ( & $theme_registry ) {
// Move our preprocess to run after
// content_translation_preprocess_language_content_settings_table().
if ( ! empty ( $theme_registry [ 'language_content_settings_table' ][ 'preprocess functions' ])) {
$preprocess_functions = & $theme_registry [ 'language_content_settings_table' ][ 'preprocess functions' ];
$index = array_search ( 'layout_builder_preprocess_language_content_settings_table' , $preprocess_functions );
if ( $index !== FALSE ) {
unset ( $preprocess_functions [ $index ]);
$preprocess_functions [] = 'layout_builder_preprocess_language_content_settings_table' ;
}
}
}
/**
* Implements hook_preprocess_HOOK () for language - content - settings - table . html . twig .
*/
function layout_builder_preprocess_language_content_settings_table ( & $variables ) {
foreach ( $variables [ 'build' ][ '#rows' ] as & $row ) {
if ( isset ( $row [ '#field_name' ]) && $row [ '#field_name' ] === OverridesSectionStorage :: FIELD_NAME ) {
// Rebuild the label to include a warning about using translations with
// layouts.
$row [ 'data' ][ 1 ][ 'data' ][ 'field' ] = [
'label' => $row [ 'data' ][ 1 ][ 'data' ][ 'field' ],
'description' => [
'#type' => 'container' ,
'#markup' => t ( '<strong>Warning</strong>: Layout Builder does not support translating layouts. (<a href="https://www.drupal.org/docs/8/core/modules/layout-builder/layout-builder-and-content-translation">online documentation</a>)' ),
'#attributes' => [
'class' => [ 'layout-builder-translation-warning' ],
],
],
];
}
}
}
2019-06-27 21:26:47 +00:00
/**
* Implements hook_theme_suggestions_HOOK_alter () .
*/
function layout_builder_theme_suggestions_field_alter ( & $suggestions , array $variables ) {
$element = $variables [ 'element' ];
if ( isset ( $element [ '#third_party_settings' ][ 'layout_builder' ][ 'view_mode' ])) {
// See system_theme_suggestions_field().
$suggestions [] = 'field__' . $element [ '#entity_type' ] . '__' . $element [ '#field_name' ] . '__' . $element [ '#bundle' ] . '__' . $element [ '#third_party_settings' ][ 'layout_builder' ][ 'view_mode' ];
}
return $suggestions ;
}
Issue #2921810 by claudiu.cristea, nod_, seanB, yogeshmpawar, dww, Wilfred Waltman, joelpittet, askibinski, ankithashetty, ravi.shankar, jonathanshaw, alexpott, kostyashupenko, webchick, danflanagan8, catch, droplet, larowlan, mpdonadio, jhedstrom, AaronMcHale, dawehner, Wim Leers, ckrina, worldlinemine: Allow TimestampFormatter to show as a fully cacheable time difference with JS
2023-03-03 16:35:58 +00:00
/**
* Implements hook_ENTITY_TYPE_presave () for entity_view_display entities .
*
* Provides a BC layer for modules providing old configurations .
*
* @ see https :// www . drupal . org / node / 2993639
*
* @ todo Remove this BC layer in drupal : 11.0 . 0.
*/
function layout_builder_entity_view_display_presave ( EntityViewDisplayInterface $entity_view_display ) : void {
if ( ! $entity_view_display instanceof LayoutEntityDisplayInterface || ! $entity_view_display -> isLayoutBuilderEnabled ()) {
return ;
}
/** @var \Drupal\Core\Field\FormatterPluginManager $field_formatter_manager */
$field_formatter_manager = \Drupal :: service ( 'plugin.manager.field.formatter' );
foreach ( $entity_view_display -> getSections () as $section ) {
foreach ( $section -> getComponents () as $component ) {
if ( str_starts_with ( $component -> getPluginId (), 'field_block:' )) {
$configuration = $component -> get ( 'configuration' );
$formatter =& $configuration [ 'formatter' ];
if ( $formatter && isset ( $formatter [ 'type' ])) {
$plugin_definition = $field_formatter_manager -> getDefinition ( $formatter [ 'type' ], FALSE );
// Check also potential plugins extending TimestampFormatter.
if ( ! $plugin_definition || ! is_a ( $plugin_definition [ 'class' ], TimestampFormatter :: class , TRUE )) {
continue ;
}
if ( ! isset ( $formatter [ 'settings' ][ 'tooltip' ]) || ! isset ( $formatter [ 'settings' ][ 'time_diff' ])) {
Issue #3048495 by jonathan1055, quietone, rajandro, Spokje, Pooja Ganjage, andypost, kishor_kolekar, msuthars, munish.kumar, ankithashetty, ayushmishra206, ravi.shankar, naveenvalecha, longwave, Gábor Hojtsy, alexpott, smustgrave, Lendude, xjm, adityasingh, daffie: Fix Drupal.Semantics.FunctionTriggerError coding standard
2023-09-26 15:28:55 +00:00
@ trigger_error ( " Using the 'timestamp' formatter plugin without the 'tooltip' and 'time_diff' settings is deprecated in drupal:10.1.0 and is required in drupal:11.0.0. See https://www.drupal.org/node/2993639 " , E_USER_DEPRECATED );
Issue #2921810 by claudiu.cristea, nod_, seanB, yogeshmpawar, dww, Wilfred Waltman, joelpittet, askibinski, ankithashetty, ravi.shankar, jonathanshaw, alexpott, kostyashupenko, webchick, danflanagan8, catch, droplet, larowlan, mpdonadio, jhedstrom, AaronMcHale, dawehner, Wim Leers, ckrina, worldlinemine: Allow TimestampFormatter to show as a fully cacheable time difference with JS
2023-03-03 16:35:58 +00:00
$formatter [ 'settings' ] += $plugin_definition [ 'class' ] :: defaultSettings ();
// Existing timestamp formatters don't have tooltip.
$formatter [ 'settings' ][ 'tooltip' ][ 'date_format' ] = '' ;
$component -> set ( 'configuration' , $configuration );
}
}
}
}
}
}