Skip to content
Snippets Groups Projects
Commit fe516c1a authored by catch's avatar catch
Browse files

Issue #3264633 by mstrelan, Spokje, dww, larowlan, catch, tim.plunkett,...

Issue #3264633 by mstrelan, Spokje, dww, larowlan, catch, tim.plunkett, bbrala, xjm: Remove \Drupal\layout_builder\QuickEditIntegration and refactor it so that quickedit contrib provides the integration with layout builder
parent 386d79e2
Branches
Tags
37 merge requests!12227Issue #3181946 by jonmcl, mglaman,!7471uncessary 5 files are moved from media-library folder to misc folder,!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!3291Issue #3336463: Rewrite rules for gzipped CSS and JavaScript aggregates never match,!3143Issue #3313342: [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1 LayoutBuilderUiCacheContext.php on line 28,!3102Issue #3164428 by DonAtt, longwave, sahil.goyal, Anchal_gupta, alexpott: Use...,!2853#3274419 Makes BaseFieldOverride inherit the internal property from the base field.,!2719Issue #3110137: Remove Classy from core.,!2437Issue #3238257 by hooroomoo, Wim Leers: Fragment link pointing to <textarea>...,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2074Issue #2707689: NodeForm::actions() checks for delete access on new entities,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1254Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!957Added throwing of InvalidPluginDefinitionException from getDefinition().,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!873Issue #2875228: Site install not using batch API service,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!712Issue #2909128: Autocomplete intermittent on Chrome Android,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
Showing
with 243 additions and 64 deletions
......@@ -192,7 +192,7 @@ protected function serializeField($field, array $context, $format) {
// @todo Replace this workaround after https://www.drupal.org/node/3043245
// or remove the need for this in https://www.drupal.org/node/2942975.
// See \Drupal\layout_builder\Normalizer\LayoutEntityDisplayNormalizer.
if ($context['resource_object']->getResourceType()->getDeserializationTargetClass() === 'Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay' && $context['resource_object']->getField('third_party_settings') === $field) {
if (is_a($context['resource_object']->getResourceType()->getDeserializationTargetClass(), 'Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay', TRUE) && $context['resource_object']->getField('third_party_settings') === $field) {
unset($field['layout_builder']['sections']);
}
......
......@@ -26,7 +26,6 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
use Drupal\layout_builder\QuickEditIntegration;
/**
* Implements hook_help().
......@@ -162,12 +161,6 @@ function layout_builder_entity_view_alter(array &$build, EntityInterface $entity
if ($display instanceof LayoutBuilderEntityViewDisplay && strpos($route_name, 'layout_builder.') === 0) {
unset($build['#contextual_links']);
}
if (\Drupal::moduleHandler()->moduleExists('quickedit')) {
/** @var \Drupal\layout_builder\QuickEditIntegration $quick_edit_integration */
$quick_edit_integration = \Drupal::classResolver(QuickEditIntegration::class);
$quick_edit_integration->entityViewAlter($build, $entity, $display);
}
}
/**
......@@ -351,15 +344,6 @@ function layout_builder_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMa
}
}
/**
* Implements hook_quickedit_render_field().
*/
function layout_builder_quickedit_render_field(EntityInterface $entity, $field_name, $view_mode_id, $langcode) {
/** @var \Drupal\layout_builder\QuickEditIntegration $quick_edit_integration */
$quick_edit_integration = \Drupal::classResolver(QuickEditIntegration::class);
return $quick_edit_integration->quickEditRenderField($entity, $field_name, $view_mode_id, $langcode);
}
/**
* Implements hook_entity_translation_create().
*/
......
......@@ -18,7 +18,6 @@
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\layout_builder\LayoutEntityHelperTrait;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
use Drupal\layout_builder\QuickEditIntegration;
use Drupal\layout_builder\Section;
use Drupal\layout_builder\SectionComponent;
use Drupal\layout_builder\SectionListTrait;
......@@ -473,7 +472,7 @@ private function sectionStorageManager() {
* {@inheritdoc}
*/
public function getComponent($name) {
if ($this->isLayoutBuilderEnabled() && $section_component = $this->getQuickEditSectionComponent() ?: $this->getSectionComponentForFieldName($name)) {
if ($this->isLayoutBuilderEnabled() && $section_component = $this->getSectionComponentForFieldName($name)) {
$plugin = $section_component->getPlugin();
if ($plugin instanceof ConfigurableInterface) {
$configuration = $plugin->getConfiguration();
......@@ -485,43 +484,6 @@ public function getComponent($name) {
return parent::getComponent($name);
}
/**
* Returns the Quick Edit formatter settings.
*
* @return \Drupal\layout_builder\SectionComponent|null
* The section component if it is available.
*
* @see \Drupal\layout_builder\QuickEditIntegration::entityViewAlter()
* @see \Drupal\quickedit\MetadataGenerator::generateFieldMetadata()
*/
private function getQuickEditSectionComponent() {
// To determine the Quick Edit view_mode ID we need an originalMode set.
if ($original_mode = $this->getOriginalMode()) {
$parts = explode('-', $original_mode);
// The Quick Edit view mode ID is created by
// \Drupal\layout_builder\QuickEditIntegration::entityViewAlter()
// concatenating together the information we need to retrieve the Layout
// Builder component. It follows the structure prescribed by the
// documentation of hook_quickedit_render_field().
if (count($parts) === 6 && $parts[0] === 'layout_builder') {
[, $delta, $component_uuid, $entity_id] = QuickEditIntegration::deconstructViewModeId($original_mode);
$entity = $this->entityTypeManager()->getStorage($this->getTargetEntityTypeId())->load($entity_id);
$sections = $this->getEntitySections($entity);
if (isset($sections[$delta])) {
$component = $sections[$delta]->getComponent($component_uuid);
$plugin = $component->getPlugin();
// We only care about FieldBlock because these are only components
// that provide Quick Edit integration: Quick Edit enables in-place
// editing of fields of entities, not of anything else.
if ($plugin instanceof DerivativeInspectionInterface && $plugin->getBaseId() === 'field_block') {
return $component;
}
}
}
}
return NULL;
}
/**
* Gets the component for a given field name if any.
*
......
......@@ -16,6 +16,9 @@
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\quickedit\Entity\QuickEditLayoutBuilderEntityViewDisplay;
use Drupal\quickedit\LayoutBuilderIntegration;
/**
* Implements hook_help().
......@@ -174,10 +177,28 @@ function quickedit_preprocess_field(&$variables) {
}
}
/**
* Implements hook_entity_type_alter().
*/
function quickedit_entity_type_alter(array &$entity_types) {
if (\Drupal::moduleHandler()->moduleExists('layout_builder')) {
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
if ($entity_types['entity_view_display']->getClass() === LayoutBuilderEntityViewDisplay::class) {
$entity_types['entity_view_display']->setClass(QuickEditLayoutBuilderEntityViewDisplay::class);
}
}
}
/**
* Implements hook_entity_view_alter().
*/
function quickedit_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
if (\Drupal::moduleHandler()->moduleExists('layout_builder')) {
/** @var \Drupal\quickedit\LayoutBuilderIntegration $layout_builder_integration */
$layout_builder_integration = \Drupal::classResolver(LayoutBuilderIntegration::class);
$layout_builder_integration->entityViewAlter($build, $entity, $display);
}
if (isset($build['#embed'])) {
return;
}
......@@ -189,3 +210,12 @@ function quickedit_entity_view_alter(&$build, EntityInterface $entity, EntityVie
$build['#attributes']['data-quickedit-entity-id'] = $entity->getEntityTypeId() . '/' . $entity->id();
}
/**
* Implements hook_quickedit_render_field().
*/
function layout_builder_quickedit_render_field(EntityInterface $entity, $field_name, $view_mode_id, $langcode) {
/** @var \Drupal\quickedit\LayoutBuilderIntegration $layout_builder_integration */
$layout_builder_integration = \Drupal::classResolver(LayoutBuilderIntegration::class);
return $layout_builder_integration->quickEditRenderField($entity, $field_name, $view_mode_id, $langcode);
}
<?php
namespace Drupal\quickedit\Entity;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\DerivativeInspectionInterface;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\quickedit\LayoutBuilderIntegration;
/**
* Provides an entity view display entity that has a layout with quickedit.
*/
class QuickEditLayoutBuilderEntityViewDisplay extends LayoutBuilderEntityViewDisplay {
/**
* {@inheritdoc}
*/
public function getComponent($name) {
if ($this->isLayoutBuilderEnabled() && $section_component = $this->getQuickEditSectionComponent()) {
$plugin = $section_component->getPlugin();
if ($plugin instanceof ConfigurableInterface) {
$configuration = $plugin->getConfiguration();
if (isset($configuration['formatter'])) {
return $configuration['formatter'];
}
}
}
return parent::getComponent($name);
}
/**
* Returns the Quick Edit formatter settings.
*
* @return \Drupal\layout_builder\SectionComponent|null
* The section component if it is available.
*
* @see \Drupal\quickedit\LayoutBuilderIntegration::entityViewAlter()
* @see \Drupal\quickedit\MetadataGenerator::generateFieldMetadata()
*/
private function getQuickEditSectionComponent() {
// To determine the Quick Edit view_mode ID we need an originalMode set.
if ($original_mode = $this->getOriginalMode()) {
$parts = explode('-', $original_mode);
// The Quick Edit view mode ID is created by
// \Drupal\quickedit\LayoutBuilderIntegration::entityViewAlter()
// concatenating together the information we need to retrieve the Layout
// Builder component. It follows the structure prescribed by the
// documentation of hook_quickedit_render_field().
if (count($parts) === 6 && $parts[0] === 'layout_builder') {
[, $delta, $component_uuid, $entity_id] = LayoutBuilderIntegration::deconstructViewModeId($original_mode);
$entity = $this->entityTypeManager()->getStorage($this->getTargetEntityTypeId())->load($entity_id);
$sections = $this->getEntitySections($entity);
if (isset($sections[$delta])) {
$component = $sections[$delta]->getComponent($component_uuid);
$plugin = $component->getPlugin();
// We only care about FieldBlock because these are only components
// that provide Quick Edit integration: Quick Edit enables in-place
// editing of fields of entities, not of anything else.
if ($plugin instanceof DerivativeInspectionInterface && $plugin->getBaseId() === 'field_block') {
return $component;
}
}
}
}
return NULL;
}
}
<?php
namespace Drupal\layout_builder;
namespace Drupal\quickedit;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheableMetadata;
......@@ -19,12 +19,12 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Helper methods for Quick Edit module integration.
* Helper methods for Layout Builder module integration.
*
* @internal
* This is an internal utility class wrapping hook implementations.
*/
class QuickEditIntegration implements ContainerInjectionInterface {
class LayoutBuilderIntegration implements ContainerInjectionInterface {
use LoggerChannelTrait;
......@@ -50,7 +50,7 @@ class QuickEditIntegration implements ContainerInjectionInterface {
protected $entityTypeManager;
/**
* Constructs a new QuickEditIntegration object.
* Constructs a new LayoutBuilderIntegration object.
*
* @param \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface $section_storage_manager
* The section storage manager.
......@@ -77,7 +77,7 @@ public static function create(ContainerInterface $container) {
}
/**
* Alters the entity view build for Quick Edit compatibility.
* Alters the entity view build for Layout Builder compatibility.
*
* When rendering fields outside of normal view modes, Quick Edit requires
* that modules identify themselves with a view mode ID in the format
......@@ -191,7 +191,7 @@ public function entityViewAlter(array &$build, EntityInterface $entity, EntityVi
* @return string
* The Quick Edit view mode ID.
*
* @see \Drupal\layout_builder\QuickEditIntegration::deconstructViewModeId()
* @see \Drupal\quickedit\LayoutBuilderIntegration::deconstructViewModeId()
*/
private static function getViewModeId(EntityInterface $entity, EntityViewDisplayInterface $display, $delta, $component_uuid, $sections_hash) {
return implode('-', [
......@@ -216,7 +216,7 @@ private static function getViewModeId(EntityInterface $entity, EntityViewDisplay
* An array containing the entity view mode ID, the delta, the component
* UUID, and the entity ID.
*
* @see \Drupal\layout_builder\QuickEditIntegration::getViewModeId()
* @see \Drupal\quickedit\LayoutBuilderIntegration::getViewModeId()
*/
public static function deconstructViewModeId($quick_edit_view_mode_id) {
[, $entity_view_mode_id, $delta, $component_uuid, $entity_id] = explode('-', $quick_edit_view_mode_id, 7);
......
<?php
namespace Drupal\Tests\quickedit\Functional\Jsonapi;
use Drupal\Tests\layout_builder\Functional\Jsonapi\LayoutBuilderEntityViewDisplayTest;
/**
* JSON:API integration test for the "EntityViewDisplay" config entity type.
*
* @group jsonapi
* @group layout_builder
* @group quickedit
*/
class QuickEditLayoutBuilderEntityViewDisplayTest extends LayoutBuilderEntityViewDisplayTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['quickedit'];
}
<?php
namespace Drupal\Tests\quickedit\Functional\Rest;
use Drupal\Tests\layout_builder\Functional\Rest\LayoutBuilderEntityViewDisplayJsonAnonTest;
/**
* @group quickedit
* @group layout_builder
* @group rest
*/
class QuickEditLayoutBuilderEntityViewDisplayJsonAnonTest extends LayoutBuilderEntityViewDisplayJsonAnonTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['quickedit'];
}
<?php
namespace Drupal\Tests\quickedit\Functional\Rest;
use Drupal\Tests\layout_builder\Functional\Rest\LayoutBuilderEntityViewDisplayJsonBasicAuthTest;
/**
* @group quickedit
* @group layout_builder
* @group rest
*/
class QuickEditLayoutBuilderEntityViewDisplayJsonBasicAuthTest extends LayoutBuilderEntityViewDisplayJsonBasicAuthTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['quickedit'];
}
<?php
namespace Drupal\Tests\quickedit\Functional\Rest;
use Drupal\Tests\layout_builder\Functional\Rest\LayoutBuilderEntityViewDisplayJsonCookieTest;
/**
* @group quickedit
* @group layout_builder
* @group rest
*/
class QuickEditLayoutBuilderEntityViewDisplayJsonCookieTest extends LayoutBuilderEntityViewDisplayJsonCookieTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['quickedit'];
}
<?php
namespace Drupal\Tests\quickedit\Functional\Rest;
use Drupal\Tests\layout_builder\Functional\Rest\LayoutBuilderEntityViewDisplayXmlAnonTest;
/**
* @group quickedit
* @group layout_builder
* @group rest
*/
class QuickEditLayoutBuilderEntityViewDisplayXmlAnonTest extends LayoutBuilderEntityViewDisplayXmlAnonTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['quickedit'];
}
<?php
namespace Drupal\Tests\quickedit\Functional\Rest;
use Drupal\Tests\layout_builder\Functional\Rest\LayoutBuilderEntityViewDisplayXmlBasicAuthTest;
/**
* @group quickedit
* @group layout_builder
* @group rest
*/
class QuickEditLayoutBuilderEntityViewDisplayXmlBasicAuthTest extends LayoutBuilderEntityViewDisplayXmlBasicAuthTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['quickedit'];
}
<?php
namespace Drupal\Tests\quickedit\Functional\Rest;
use Drupal\Tests\layout_builder\Functional\Rest\LayoutBuilderEntityViewDisplayXmlCookieTest;
/**
* @group quickedit
* @group layout_builder
* @group rest
*/
class QuickEditLayoutBuilderEntityViewDisplayXmlCookieTest extends LayoutBuilderEntityViewDisplayXmlCookieTest {
/**
* {@inheritdoc}
*/
protected static $modules = ['quickedit'];
}
......@@ -14,7 +14,7 @@
/**
* @group quickedit
*/
class QuickEditIntegrationTest extends QuickEditJavascriptTestBase {
class LayoutBuilderIntegrationTest extends QuickEditJavascriptTestBase {
use EntityReferenceTestTrait;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment