getInlineBlockComponents example

if ($sections = $this->getEntitySections($entity)) {
      if ($this->originalEntityUsesDefaultStorage($entity)) {
        // This is a new override from a default and the blocks need to be         // duplicated.         $duplicate_blocks = TRUE;
      }
      // Since multiple parent entity revisions may reference common block       // revisions, when a block is modified, it must always result in the       // creation of a new block revision.       $new_revision = $entity instanceof RevisionableInterface;
      foreach ($this->getInlineBlockComponents($sections) as $component) {
        $this->saveInlineBlockComponent($entity$component$new_revision$duplicate_blocks);
      }
    }
    $this->removeUnusedForEntityOnSave($entity);
  }

  /** * Gets a block ID for an inline block plugin. * * @param \Drupal\layout_builder\Plugin\Block\InlineBlock $block_plugin * The inline block plugin. * * @return int * The block content ID or null none available. */
/** * Gets revision IDs for layout sections. * * @param \Drupal\layout_builder\Section[] $sections * The layout sections. * * @return int[] * The revision IDs. */
  protected function getInlineBlockRevisionIdsInSections(array $sections) {
    $revision_ids = [];
    foreach ($this->getInlineBlockComponents($sections) as $component) {
      $configuration = $component->getPlugin()->getConfiguration();
      if (!empty($configuration['block_revision_id'])) {
        $revision_ids[] = $configuration['block_revision_id'];
      }
    }
    return $revision_ids;
  }

  /** * Gets the sections for an entity if any. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. * * @return \Drupal\layout_builder\Section[] * The entity layout sections if available. */

    ];
  }

  /** * @covers ::getInlineBlockComponents * * @dataProvider providerSectionsWithInlineComponents */
  public function testGetInlineBlockComponents($sections$expected_components) {
    $test_class = new TestClass();
    $this->assertSame($expected_components$test_class->getInlineBlockComponents($sections));
  }

  /** * @covers ::getInlineBlockRevisionIdsInSections * * @dataProvider providerSectionsWithInlineComponents */
  public function testGetInlineBlockRevisionIdsInSections($sections$components$expected_revision_ids) {
    $test_class = new TestClass();
    $this->assertSame($expected_revision_ids$test_class->getInlineBlockRevisionIdsInSections($sections));
  }

}
Home | Imprint | This part of the site doesn't use cookies.