Chris@14
|
1 <?php
|
Chris@14
|
2
|
Chris@14
|
3 /**
|
Chris@14
|
4 * @file
|
Chris@14
|
5 * Provides hook implementations for Layout Builder.
|
Chris@14
|
6 */
|
Chris@14
|
7
|
Chris@18
|
8 use Drupal\Core\Breadcrumb\Breadcrumb;
|
Chris@18
|
9 use Drupal\Core\Cache\CacheableMetadata;
|
Chris@17
|
10 use Drupal\Core\Entity\EntityInterface;
|
Chris@18
|
11 use Drupal\Core\Entity\FieldableEntityInterface;
|
Chris@14
|
12 use Drupal\Core\Form\FormStateInterface;
|
Chris@18
|
13 use Drupal\Core\Link;
|
Chris@17
|
14 use Drupal\Core\Render\Element;
|
Chris@14
|
15 use Drupal\Core\Routing\RouteMatchInterface;
|
Chris@14
|
16 use Drupal\Core\Url;
|
Chris@14
|
17 use Drupal\field\FieldConfigInterface;
|
Chris@14
|
18 use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
|
Chris@14
|
19 use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage;
|
Chris@18
|
20 use Drupal\layout_builder\Form\DefaultsEntityForm;
|
Chris@14
|
21 use Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm;
|
Chris@18
|
22 use Drupal\layout_builder\Form\OverridesEntityForm;
|
Chris@17
|
23 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
Chris@17
|
24 use Drupal\layout_builder\Plugin\Block\ExtraFieldBlock;
|
Chris@17
|
25 use Drupal\layout_builder\InlineBlockEntityOperations;
|
Chris@17
|
26 use Drupal\Core\Session\AccountInterface;
|
Chris@17
|
27 use Drupal\Core\Access\AccessResult;
|
Chris@17
|
28 use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
|
Chris@18
|
29 use Drupal\layout_builder\QuickEditIntegration;
|
Chris@14
|
30
|
Chris@14
|
31 /**
|
Chris@14
|
32 * Implements hook_help().
|
Chris@14
|
33 */
|
Chris@14
|
34 function layout_builder_help($route_name, RouteMatchInterface $route_match) {
|
Chris@14
|
35 // Add help text to the Layout Builder UI.
|
Chris@14
|
36 if ($route_match->getRouteObject()->getOption('_layout_builder')) {
|
Chris@14
|
37 $output = '<p>' . t('This layout builder tool allows you to configure the layout of the main content area.') . '</p>';
|
Chris@14
|
38 if (\Drupal::currentUser()->hasPermission('administer blocks')) {
|
Chris@14
|
39 $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>';
|
Chris@14
|
40 }
|
Chris@14
|
41 else {
|
Chris@14
|
42 $output .= '<p>' . t('To manage other areas of the page, use the block administration page.') . '</p>';
|
Chris@14
|
43 }
|
Chris@18
|
44 $output .= '<p>' . t('Forms and links inside the content of the layout builder tool have been disabled.') . '</p>';
|
Chris@14
|
45 return $output;
|
Chris@14
|
46 }
|
Chris@14
|
47
|
Chris@14
|
48 switch ($route_name) {
|
Chris@14
|
49 case 'help.page.layout_builder':
|
Chris@14
|
50 $output = '<h3>' . t('About') . '</h3>';
|
Chris@18
|
51 $output .= '<p>' . t('Layout Builder allows you to use layouts to customize how content, custom 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>';
|
Chris@18
|
52 $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>';
|
Chris@18
|
53 $output .= '<h3>' . t('Uses') . '</h3>';
|
Chris@18
|
54 $output .= '<dl>';
|
Chris@18
|
55 $output .= '<dt>' . t('Default layouts') . '</dt>';
|
Chris@18
|
56 $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>';
|
Chris@18
|
57 $output .= '<dt>' . t('Overridden layouts') . '</dt>';
|
Chris@18
|
58 $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>';
|
Chris@18
|
59 $output .= '<dt>' . t('User permissions') . '</dt>';
|
Chris@18
|
60 $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.', [
|
Chris@18
|
61 ':permissions' => Url::fromRoute('user.admin_permissions', [], ['fragment' => 'module-layout_builder'])->toString(),
|
Chris@18
|
62 ':layout-builder-permissions' => 'https://www.drupal.org/docs/8/core/modules/layout-builder/configuring-layout-builder-permissions',
|
Chris@18
|
63 ]) . '</dd>';
|
Chris@18
|
64 $output .= '</dl>';
|
Chris@14
|
65 return $output;
|
Chris@14
|
66 }
|
Chris@14
|
67 }
|
Chris@14
|
68
|
Chris@14
|
69 /**
|
Chris@14
|
70 * Implements hook_entity_type_alter().
|
Chris@14
|
71 */
|
Chris@14
|
72 function layout_builder_entity_type_alter(array &$entity_types) {
|
Chris@14
|
73 /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
|
Chris@14
|
74 $entity_types['entity_view_display']
|
Chris@14
|
75 ->setClass(LayoutBuilderEntityViewDisplay::class)
|
Chris@14
|
76 ->setStorageClass(LayoutBuilderEntityViewDisplayStorage::class)
|
Chris@18
|
77 ->setFormClass('layout_builder', DefaultsEntityForm::class)
|
Chris@14
|
78 ->setFormClass('edit', LayoutBuilderEntityViewDisplayForm::class);
|
Chris@18
|
79
|
Chris@18
|
80 // Ensure every fieldable entity type has a layout form.
|
Chris@18
|
81 foreach ($entity_types as $entity_type) {
|
Chris@18
|
82 if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) {
|
Chris@18
|
83 $entity_type->setFormClass('layout_builder', OverridesEntityForm::class);
|
Chris@18
|
84 }
|
Chris@18
|
85 }
|
Chris@14
|
86 }
|
Chris@14
|
87
|
Chris@14
|
88 /**
|
Chris@14
|
89 * Implements hook_form_FORM_ID_alter() for \Drupal\field_ui\Form\EntityFormDisplayEditForm.
|
Chris@14
|
90 */
|
Chris@14
|
91 function layout_builder_form_entity_form_display_edit_form_alter(&$form, FormStateInterface $form_state) {
|
Chris@14
|
92 // Hides the Layout Builder field. It is rendered directly in
|
Chris@14
|
93 // \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildMultiple().
|
Chris@17
|
94 unset($form['fields'][OverridesSectionStorage::FIELD_NAME]);
|
Chris@17
|
95 $key = array_search(OverridesSectionStorage::FIELD_NAME, $form['#fields']);
|
Chris@14
|
96 if ($key !== FALSE) {
|
Chris@14
|
97 unset($form['#fields'][$key]);
|
Chris@14
|
98 }
|
Chris@14
|
99 }
|
Chris@14
|
100
|
Chris@14
|
101 /**
|
Chris@14
|
102 * Implements hook_field_config_insert().
|
Chris@14
|
103 */
|
Chris@14
|
104 function layout_builder_field_config_insert(FieldConfigInterface $field_config) {
|
Chris@14
|
105 // Clear the sample entity for this entity type and bundle.
|
Chris@14
|
106 $sample_entity_generator = \Drupal::service('layout_builder.sample_entity_generator');
|
Chris@14
|
107 $sample_entity_generator->delete($field_config->getTargetEntityTypeId(), $field_config->getTargetBundle());
|
Chris@14
|
108 \Drupal::service('plugin.manager.block')->clearCachedDefinitions();
|
Chris@14
|
109 }
|
Chris@14
|
110
|
Chris@14
|
111 /**
|
Chris@14
|
112 * Implements hook_field_config_delete().
|
Chris@14
|
113 */
|
Chris@14
|
114 function layout_builder_field_config_delete(FieldConfigInterface $field_config) {
|
Chris@14
|
115 // Clear the sample entity for this entity type and bundle.
|
Chris@14
|
116 $sample_entity_generator = \Drupal::service('layout_builder.sample_entity_generator');
|
Chris@14
|
117 $sample_entity_generator->delete($field_config->getTargetEntityTypeId(), $field_config->getTargetBundle());
|
Chris@14
|
118 \Drupal::service('plugin.manager.block')->clearCachedDefinitions();
|
Chris@14
|
119 }
|
Chris@17
|
120
|
Chris@17
|
121 /**
|
Chris@17
|
122 * Implements hook_entity_view_alter().
|
Chris@17
|
123 *
|
Chris@17
|
124 * ExtraFieldBlock block plugins add placeholders for each extra field which is
|
Chris@17
|
125 * configured to be displayed. Those placeholders are replaced by this hook.
|
Chris@17
|
126 * Modules that implement hook_entity_extra_field_info() use their
|
Chris@17
|
127 * implementations of hook_entity_view_alter() to add the rendered output of
|
Chris@17
|
128 * the extra fields they provide, so we cannot get the rendered output of extra
|
Chris@17
|
129 * fields before this point in the view process.
|
Chris@17
|
130 * layout_builder_module_implements_alter() moves this implementation of
|
Chris@17
|
131 * hook_entity_view_alter() to the end of the list.
|
Chris@17
|
132 *
|
Chris@17
|
133 * @see \Drupal\layout_builder\Plugin\Block\ExtraFieldBlock::build()
|
Chris@17
|
134 * @see layout_builder_module_implements_alter()
|
Chris@17
|
135 */
|
Chris@17
|
136 function layout_builder_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
|
Chris@17
|
137 // Only replace extra fields when Layout Builder has been used to alter the
|
Chris@17
|
138 // build. See \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildMultiple().
|
Chris@17
|
139 if (isset($build['_layout_builder']) && !Element::isEmpty($build['_layout_builder'])) {
|
Chris@17
|
140 /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
|
Chris@17
|
141 $field_manager = \Drupal::service('entity_field.manager');
|
Chris@17
|
142 $extra_fields = $field_manager->getExtraFields($entity->getEntityTypeId(), $entity->bundle());
|
Chris@17
|
143 if (!empty($extra_fields['display'])) {
|
Chris@17
|
144 foreach ($extra_fields['display'] as $field_name => $extra_field) {
|
Chris@17
|
145 // If the extra field is not set replace with an empty array to avoid
|
Chris@17
|
146 // the placeholder text from being rendered.
|
Chris@17
|
147 $replacement = isset($build[$field_name]) ? $build[$field_name] : [];
|
Chris@17
|
148 ExtraFieldBlock::replaceFieldPlaceholder($build, $replacement, $field_name);
|
Chris@17
|
149 // After the rendered field in $build has been copied over to the
|
Chris@17
|
150 // ExtraFieldBlock block we must remove it from its original location or
|
Chris@17
|
151 // else it will be rendered twice.
|
Chris@17
|
152 unset($build[$field_name]);
|
Chris@17
|
153 }
|
Chris@17
|
154 }
|
Chris@17
|
155 }
|
Chris@18
|
156
|
Chris@18
|
157 $route_name = \Drupal::routeMatch()->getRouteName();
|
Chris@18
|
158
|
Chris@18
|
159 // If the entity is displayed within a Layout Builder block and the current
|
Chris@18
|
160 // route is in the Layout Builder UI, then remove all contextual link
|
Chris@18
|
161 // placeholders.
|
Chris@18
|
162 if ($display instanceof LayoutBuilderEntityViewDisplay && strpos($route_name, 'layout_builder.') === 0) {
|
Chris@18
|
163 unset($build['#contextual_links']);
|
Chris@18
|
164 }
|
Chris@18
|
165
|
Chris@18
|
166 if (\Drupal::moduleHandler()->moduleExists('quickedit')) {
|
Chris@18
|
167 /** @var \Drupal\layout_builder\QuickEditIntegration $quick_edit_integration */
|
Chris@18
|
168 $quick_edit_integration = \Drupal::classResolver(QuickEditIntegration::class);
|
Chris@18
|
169 $quick_edit_integration->entityViewAlter($build, $entity, $display);
|
Chris@18
|
170 }
|
Chris@18
|
171 }
|
Chris@18
|
172
|
Chris@18
|
173 /**
|
Chris@18
|
174 * Implements hook_entity_build_defaults_alter().
|
Chris@18
|
175 */
|
Chris@18
|
176 function layout_builder_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode) {
|
Chris@18
|
177 // Contextual links are removed for entities viewed in Layout Builder's UI.
|
Chris@18
|
178 // The route.name.is_layout_builder_ui cache context accounts for this
|
Chris@18
|
179 // difference.
|
Chris@18
|
180 // @see layout_builder_entity_view_alter()
|
Chris@18
|
181 // @see \Drupal\layout_builder\Cache\LayoutBuilderUiCacheContext
|
Chris@18
|
182 $build['#cache']['contexts'][] = 'route.name.is_layout_builder_ui';
|
Chris@17
|
183 }
|
Chris@17
|
184
|
Chris@17
|
185 /**
|
Chris@17
|
186 * Implements hook_builder_module_implements_alter().
|
Chris@17
|
187 */
|
Chris@17
|
188 function layout_builder_module_implements_alter(&$implementations, $hook) {
|
Chris@17
|
189 if ($hook === 'entity_view_alter') {
|
Chris@17
|
190 // Ensure that this module's implementation of hook_entity_view_alter() runs
|
Chris@17
|
191 // last so that other modules that use this hook to render extra fields will
|
Chris@17
|
192 // run before it.
|
Chris@17
|
193 $group = $implementations['layout_builder'];
|
Chris@17
|
194 unset($implementations['layout_builder']);
|
Chris@17
|
195 $implementations['layout_builder'] = $group;
|
Chris@17
|
196 }
|
Chris@17
|
197 }
|
Chris@17
|
198
|
Chris@17
|
199 /**
|
Chris@17
|
200 * Implements hook_entity_presave().
|
Chris@17
|
201 */
|
Chris@17
|
202 function layout_builder_entity_presave(EntityInterface $entity) {
|
Chris@17
|
203 if (\Drupal::moduleHandler()->moduleExists('block_content')) {
|
Chris@17
|
204 /** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */
|
Chris@17
|
205 $entity_operations = \Drupal::classResolver(InlineBlockEntityOperations::class);
|
Chris@17
|
206 $entity_operations->handlePreSave($entity);
|
Chris@17
|
207 }
|
Chris@17
|
208 }
|
Chris@17
|
209
|
Chris@17
|
210 /**
|
Chris@17
|
211 * Implements hook_entity_delete().
|
Chris@17
|
212 */
|
Chris@17
|
213 function layout_builder_entity_delete(EntityInterface $entity) {
|
Chris@17
|
214 if (\Drupal::moduleHandler()->moduleExists('block_content')) {
|
Chris@17
|
215 /** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */
|
Chris@17
|
216 $entity_operations = \Drupal::classResolver(InlineBlockEntityOperations::class);
|
Chris@17
|
217 $entity_operations->handleEntityDelete($entity);
|
Chris@17
|
218 }
|
Chris@17
|
219 }
|
Chris@17
|
220
|
Chris@17
|
221 /**
|
Chris@17
|
222 * Implements hook_cron().
|
Chris@17
|
223 */
|
Chris@17
|
224 function layout_builder_cron() {
|
Chris@17
|
225 if (\Drupal::moduleHandler()->moduleExists('block_content')) {
|
Chris@17
|
226 /** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */
|
Chris@17
|
227 $entity_operations = \Drupal::classResolver(InlineBlockEntityOperations::class);
|
Chris@17
|
228 $entity_operations->removeUnused();
|
Chris@17
|
229 }
|
Chris@17
|
230 }
|
Chris@17
|
231
|
Chris@17
|
232 /**
|
Chris@18
|
233 * Implements hook_plugin_filter_TYPE__CONSUMER_alter().
|
Chris@18
|
234 */
|
Chris@18
|
235 function layout_builder_plugin_filter_block__layout_builder_alter(array &$definitions, array $extra) {
|
Chris@18
|
236 // @todo Restore the page title block in https://www.drupal.org/node/2938129.
|
Chris@18
|
237 unset($definitions['page_title_block']);
|
Chris@18
|
238 }
|
Chris@18
|
239
|
Chris@18
|
240 /**
|
Chris@17
|
241 * Implements hook_plugin_filter_TYPE_alter().
|
Chris@17
|
242 */
|
Chris@17
|
243 function layout_builder_plugin_filter_block_alter(array &$definitions, array $extra, $consumer) {
|
Chris@17
|
244 // @todo Determine the 'inline_block' blocks should be allowed outside
|
Chris@17
|
245 // of layout_builder https://www.drupal.org/node/2979142.
|
Chris@17
|
246 if ($consumer !== 'layout_builder' || !isset($extra['list']) || $extra['list'] !== 'inline_blocks') {
|
Chris@17
|
247 foreach ($definitions as $id => $definition) {
|
Chris@17
|
248 if ($definition['id'] === 'inline_block') {
|
Chris@17
|
249 unset($definitions[$id]);
|
Chris@17
|
250 }
|
Chris@17
|
251 }
|
Chris@17
|
252 }
|
Chris@17
|
253 }
|
Chris@17
|
254
|
Chris@17
|
255 /**
|
Chris@17
|
256 * Implements hook_ENTITY_TYPE_access().
|
Chris@17
|
257 */
|
Chris@17
|
258 function layout_builder_block_content_access(EntityInterface $entity, $operation, AccountInterface $account) {
|
Chris@17
|
259 /** @var \Drupal\block_content\BlockContentInterface $entity */
|
Chris@17
|
260 if ($operation === 'view' || $entity->isReusable() || empty(\Drupal::service('inline_block.usage')->getUsage($entity->id()))) {
|
Chris@17
|
261 // If the operation is 'view' or this is reusable block or if this is
|
Chris@17
|
262 // non-reusable that isn't used by this module then don't alter the access.
|
Chris@17
|
263 return AccessResult::neutral();
|
Chris@17
|
264 }
|
Chris@17
|
265
|
Chris@18
|
266 if ($account->hasPermission('create and edit custom blocks')) {
|
Chris@17
|
267 return AccessResult::allowed();
|
Chris@17
|
268 }
|
Chris@17
|
269 return AccessResult::forbidden();
|
Chris@17
|
270 }
|
Chris@17
|
271
|
Chris@17
|
272 /**
|
Chris@17
|
273 * Implements hook_plugin_filter_TYPE__CONSUMER_alter().
|
Chris@17
|
274 */
|
Chris@17
|
275 function layout_builder_plugin_filter_block__block_ui_alter(array &$definitions, array $extra) {
|
Chris@17
|
276 foreach ($definitions as $id => $definition) {
|
Chris@18
|
277 // Filter out any layout_builder-provided block that has required context
|
Chris@18
|
278 // definitions.
|
Chris@18
|
279 if ($definition['provider'] === 'layout_builder' && !empty($definition['context_definitions'])) {
|
Chris@18
|
280 /** @var \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context_definition */
|
Chris@18
|
281 foreach ($definition['context_definitions'] as $context_definition) {
|
Chris@18
|
282 if ($context_definition->isRequired()) {
|
Chris@17
|
283 unset($definitions[$id]);
|
Chris@17
|
284 break;
|
Chris@17
|
285 }
|
Chris@17
|
286 }
|
Chris@17
|
287 }
|
Chris@17
|
288 }
|
Chris@17
|
289 }
|
Chris@18
|
290
|
Chris@18
|
291 /**
|
Chris@18
|
292 * Implements hook_plugin_filter_TYPE__CONSUMER_alter().
|
Chris@18
|
293 */
|
Chris@18
|
294 function layout_builder_plugin_filter_layout__layout_builder_alter(array &$definitions, array $extra) {
|
Chris@18
|
295 // Remove layouts provide by layout discovery that are not needed because of
|
Chris@18
|
296 // layouts provided by this module.
|
Chris@18
|
297 $duplicate_layouts = [
|
Chris@18
|
298 'layout_twocol',
|
Chris@18
|
299 'layout_twocol_bricks',
|
Chris@18
|
300 'layout_threecol_25_50_25',
|
Chris@18
|
301 'layout_threecol_33_34_33',
|
Chris@18
|
302 ];
|
Chris@18
|
303
|
Chris@18
|
304 foreach ($duplicate_layouts as $duplicate_layout) {
|
Chris@18
|
305 /** @var \Drupal\Core\Layout\LayoutDefinition[] $definitions */
|
Chris@18
|
306 if (isset($definitions[$duplicate_layout])) {
|
Chris@18
|
307 if ($definitions[$duplicate_layout]->getProvider() === 'layout_discovery') {
|
Chris@18
|
308 unset($definitions[$duplicate_layout]);
|
Chris@18
|
309 }
|
Chris@18
|
310 }
|
Chris@18
|
311 }
|
Chris@18
|
312
|
Chris@18
|
313 // Move the one column layout to the top.
|
Chris@18
|
314 if (isset($definitions['layout_onecol']) && $definitions['layout_onecol']->getProvider() === 'layout_discovery') {
|
Chris@18
|
315 $one_col = $definitions['layout_onecol'];
|
Chris@18
|
316 unset($definitions['layout_onecol']);
|
Chris@18
|
317 $definitions = [
|
Chris@18
|
318 'layout_onecol' => $one_col,
|
Chris@18
|
319 ] + $definitions;
|
Chris@18
|
320 }
|
Chris@18
|
321 }
|
Chris@18
|
322
|
Chris@18
|
323 /**
|
Chris@18
|
324 * Implements hook_plugin_filter_TYPE_alter().
|
Chris@18
|
325 */
|
Chris@18
|
326 function layout_builder_plugin_filter_layout_alter(array &$definitions, array $extra, $consumer) {
|
Chris@18
|
327 // Hide the blank layout plugin from listings.
|
Chris@18
|
328 unset($definitions['layout_builder_blank']);
|
Chris@18
|
329 }
|
Chris@18
|
330
|
Chris@18
|
331 /**
|
Chris@18
|
332 * Implements hook_system_breadcrumb_alter().
|
Chris@18
|
333 */
|
Chris@18
|
334 function layout_builder_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) {
|
Chris@18
|
335 // Remove the extra 'Manage display' breadcrumb for Layout Builder defaults.
|
Chris@18
|
336 if ($route_match->getRouteObject()->hasOption('_layout_builder') && $route_match->getParameter('section_storage_type') === 'defaults') {
|
Chris@18
|
337 $links = array_filter($breadcrumb->getLinks(), function (Link $link) use ($route_match) {
|
Chris@18
|
338 $entity_type_id = $route_match->getParameter('entity_type_id');
|
Chris@18
|
339 return $link->getUrl()->getRouteName() !== "entity.entity_view_display.$entity_type_id.default";
|
Chris@18
|
340 });
|
Chris@18
|
341 // Links cannot be removed from an existing breadcrumb object. Create a new
|
Chris@18
|
342 // object but carry over the cacheable metadata.
|
Chris@18
|
343 $cacheability = CacheableMetadata::createFromObject($breadcrumb);
|
Chris@18
|
344 $breadcrumb = new Breadcrumb();
|
Chris@18
|
345 $breadcrumb->setLinks($links);
|
Chris@18
|
346 $breadcrumb->addCacheableDependency($cacheability);
|
Chris@18
|
347 }
|
Chris@18
|
348 }
|
Chris@18
|
349
|
Chris@18
|
350 /**
|
Chris@18
|
351 * Implements hook_quickedit_render_field().
|
Chris@18
|
352 */
|
Chris@18
|
353 function layout_builder_quickedit_render_field(EntityInterface $entity, $field_name, $view_mode_id, $langcode) {
|
Chris@18
|
354 /** @var \Drupal\layout_builder\QuickEditIntegration $quick_edit_integration */
|
Chris@18
|
355 $quick_edit_integration = \Drupal::classResolver(QuickEditIntegration::class);
|
Chris@18
|
356 return $quick_edit_integration->quickEditRenderField($entity, $field_name, $view_mode_id, $langcode);
|
Chris@18
|
357 }
|
Chris@18
|
358
|
Chris@18
|
359 /**
|
Chris@18
|
360 * Implements hook_entity_translation_create().
|
Chris@18
|
361 */
|
Chris@18
|
362 function layout_builder_entity_translation_create(EntityInterface $translation) {
|
Chris@18
|
363 /** @var \Drupal\Core\Entity\FieldableEntityInterface $translation */
|
Chris@18
|
364 if ($translation->hasField(OverridesSectionStorage::FIELD_NAME) && $translation->getFieldDefinition(OverridesSectionStorage::FIELD_NAME)->isTranslatable()) {
|
Chris@18
|
365 // When creating a new translation do not copy untranslated sections because
|
Chris@18
|
366 // per-language layouts are not supported.
|
Chris@18
|
367 $translation->set(OverridesSectionStorage::FIELD_NAME, []);
|
Chris@18
|
368 }
|
Chris@18
|
369 }
|
Chris@18
|
370
|
Chris@18
|
371 /**
|
Chris@18
|
372 * Implements hook_theme_registry_alter().
|
Chris@18
|
373 */
|
Chris@18
|
374 function layout_builder_theme_registry_alter(&$theme_registry) {
|
Chris@18
|
375 // Move our preprocess to run after
|
Chris@18
|
376 // content_translation_preprocess_language_content_settings_table().
|
Chris@18
|
377 if (!empty($theme_registry['language_content_settings_table']['preprocess functions'])) {
|
Chris@18
|
378 $preprocess_functions = &$theme_registry['language_content_settings_table']['preprocess functions'];
|
Chris@18
|
379 $index = array_search('layout_builder_preprocess_language_content_settings_table', $preprocess_functions);
|
Chris@18
|
380 if ($index !== FALSE) {
|
Chris@18
|
381 unset($preprocess_functions[$index]);
|
Chris@18
|
382 $preprocess_functions[] = 'layout_builder_preprocess_language_content_settings_table';
|
Chris@18
|
383 }
|
Chris@18
|
384 }
|
Chris@18
|
385 }
|
Chris@18
|
386
|
Chris@18
|
387 /**
|
Chris@18
|
388 * Implements hook_preprocess_HOOK() for language-content-settings-table.html.twig.
|
Chris@18
|
389 */
|
Chris@18
|
390 function layout_builder_preprocess_language_content_settings_table(&$variables) {
|
Chris@18
|
391 foreach ($variables['build']['#rows'] as &$row) {
|
Chris@18
|
392 if (isset($row['#field_name']) && $row['#field_name'] === OverridesSectionStorage::FIELD_NAME) {
|
Chris@18
|
393 // Rebuild the label to include a warning about using translations with
|
Chris@18
|
394 // layouts.
|
Chris@18
|
395 $row['data'][1]['data']['field'] = [
|
Chris@18
|
396 'label' => $row['data'][1]['data']['field'],
|
Chris@18
|
397 'description' => [
|
Chris@18
|
398 '#type' => 'container',
|
Chris@18
|
399 '#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>)'),
|
Chris@18
|
400 '#attributes' => [
|
Chris@18
|
401 'class' => ['layout-builder-translation-warning'],
|
Chris@18
|
402 ],
|
Chris@18
|
403 ],
|
Chris@18
|
404 ];
|
Chris@18
|
405 }
|
Chris@18
|
406 }
|
Chris@18
|
407 }
|