getEntitySections example

/** * Gets the IDs of the inline blocks that were removed. * * @param \Drupal\Core\Entity\EntityInterface $entity * The layout entity. * * @return int[] * The block content IDs that were removed. */
  protected function getRemovedBlockIds(EntityInterface $entity) {
    $original_sections = $this->getEntitySections($entity->original);
    $current_sections = $this->getEntitySections($entity);
    // Avoid un-needed conversion from revision IDs to block content IDs by     // first determining if there are any revisions in the original that are not     // also in the current sections.     $current_block_content_revision_ids = $this->getInlineBlockRevisionIdsInSections($current_sections);
    $original_block_content_revision_ids = $this->getInlineBlockRevisionIdsInSections($original_sections);
    if ($unused_original_revision_ids = array_diff($original_block_content_revision_ids$current_block_content_revision_ids)) {
      // If there are any revisions in the original that aren't in the current       // there may some blocks that need to be removed.       $current_block_content_ids = $this->getBlockIdsForRevisionIds($current_block_content_revision_ids);
      $unused_original_block_content_ids = $this->getBlockIdsForRevisionIds($unused_original_revision_ids);
      

  protected function isBlockRevisionUsedInEntity(EntityInterface $layout_entity, BlockContentInterface $block_content) {
    $sections_blocks_revision_ids = $this->getInlineBlockRevisionIdsInSections($this->getEntitySections($layout_entity));
    return in_array($block_content->getRevisionId()$sections_blocks_revision_ids);
  }

}
new Section('layout_onecol'),
    ];
    $this->assertCount(1, $sections);
    $section_storage->getSections()->willReturn($sections);
    $section_storage->count()->willReturn(1);

    $section_storage_manager->findByContext(Argument::cetera())->willReturn($section_storage->reveal());
    $this->container->set('plugin.manager.layout_builder.section_storage', $section_storage_manager->reveal());
    $class = new TestLayoutEntityHelperTrait();
    // Ensure that if the entity has a section storage the sections will be     // returned.     $this->assertSame($sections$class->getEntitySections($entity));

    $section_storage_manager->findByContext(Argument::cetera())->willReturn(NULL);
    $this->container->set('plugin.manager.layout_builder.section_storage', $section_storage_manager->reveal());
    // Ensure that if the entity has no section storage an empty array will be     // returned.     $this->assertSame([]$class->getEntitySections($entity));
  }

}

/** * Test class using the trait. */
Home | Imprint | This part of the site doesn't use cookies.