Skip to content
Snippets Groups Projects
Unverified Commit 21d16eed authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3483353 by a.dmitriiev, phenaproxima, atul_ghate, alexpott, roderik:...

Issue #3483353 by a.dmitriiev, phenaproxima, atul_ghate, alexpott, roderik: Remove the createCopy action from EntityDisplayBase, and make cloneAs compatible with wildcards

(cherry picked from commit 3de28c0f)
parent 41f0ccb5
No related branches found
No related tags found
1 merge request!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4
Pipeline #350132 passed with warnings
Pipeline: drupal

#350192

    Pipeline: drupal

    #350189

      Pipeline: drupal

      #350179

        +7
        ......@@ -56,6 +56,21 @@ public function apply(string $configName, mixed $value): void {
        if (empty($original)) {
        throw new ConfigActionException("Cannot clone '$configName' because it does not exist.");
        }
        // Treat the original ID like a period-separated array of strings, and
        // replace any `%` parts in the clone's ID with the corresponding part of
        // the original ID. For example, if we're cloning an entity view display
        // with the ID `node.foo.teaser`, and the clone's ID is
        // `node.%.search_result`, the final ID of the clone will be
        // `node.foo.search_result`.
        $original_id_parts = explode('.', $original->id());
        $clone_id_parts = explode('.', $value['id']);
        assert(count($original_id_parts) === count($clone_id_parts));
        foreach ($clone_id_parts as $index => $part) {
        $clone_id_parts[$index] = $part === '%' ? $original_id_parts[$index] : $part;
        }
        $value['id'] = implode('.', $clone_id_parts);
        $clone = $original->createDuplicate();
        $clone->set($original->getEntityType()->getKey('id'), $value['id']);
        ......
        ......@@ -324,7 +324,6 @@ public function toArray() {
        /**
        * {@inheritdoc}
        */
        #[ActionMethod(adminLabel: new TranslatableMarkup('Copy to another mode'), pluralize: FALSE)]
        public function createCopy($mode) {
        $display = $this->createDuplicate();
        $display->mode = $display->originalMode = $mode;
        ......
        ......@@ -93,9 +93,9 @@ public function testFailIfEntityExists(): void {
        }
        /**
        * Tests cloning entity displays, which have specialized logic for that.
        * Tests wildcard support, which allows positional tokens in the clone's ID.
        */
        public function testCloneEntityDisplay(): void {
        public function testCloneWithWildcards(): void {
        $this->container->get(ModuleInstallerInterface::class)->install(['node']);
        $this->createContentType(['type' => 'alpha']);
        $this->createContentType(['type' => 'beta']);
        ......@@ -112,17 +112,9 @@ public function testCloneEntityDisplay(): void {
        // Use the action to clone the default view displays to the `rss` view mode.
        /** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
        $manager = $this->container->get('plugin.manager.config_action');
        $manager->applyAction('cloneAs', 'core.entity_view_display.node.alpha.default', 'node.alpha.rss');
        $manager->applyAction('entity_method:core.entity_view_display:createCopy', 'core.entity_view_display.node.beta.default', 'rss');
        $manager->applyAction('cloneAs', 'core.entity_view_display.node.*.default', 'node.%.rss');
        $this->assertFalse($display_repository->getViewDisplay('node', 'alpha', 'rss')->isNew());
        $this->assertFalse($display_repository->getViewDisplay('node', 'beta', 'rss')->isNew());
        // Ensure that this also works with wildcards.
        $this->assertTrue($display_repository->getViewDisplay('node', 'alpha', 'search_result')->isNew());
        $this->assertTrue($display_repository->getViewDisplay('node', 'beta', 'search_result')->isNew());
        $manager->applyAction('entity_method:core.entity_view_display:createCopy', 'core.entity_view_display.node.*.default', 'search_result');
        $this->assertFalse($display_repository->getViewDisplay('node', 'alpha', 'search_result')->isNew());
        $this->assertFalse($display_repository->getViewDisplay('node', 'beta', 'search_result')->isNew());
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment