isOverridable example

/** * {@inheritdoc} */
  public function save() {
    return $this->getDisplay()->save();
  }

  /** * {@inheritdoc} */
  public function isOverridable() {
    return $this->getDisplay()->isOverridable();
  }

  /** * {@inheritdoc} */
  public function setOverridable($overridable = TRUE) {
    $this->getDisplay()->setOverridable($overridable);
    return $this;
  }

  /** * {@inheritdoc} */
$form['#entity_builders']['layout_builder'] = '::entityFormEntityBuild';

    // @todo Expand to work for all view modes in     // https://www.drupal.org/node/2907413.     if ($this->isCanonicalMode($this->entity->getMode())) {
      $entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId());
      $form['layout']['allow_custom'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Allow each @entity to have its layout customized.', [
          '@entity' => $entity_type->getSingularLabel(),
        ]),
        '#default_value' => $this->entity->isOverridable(),
        '#states' => [
          'disabled' => [
            ':input[name="layout[enabled]"]' => ['checked' => FALSE],
          ],
          'invisible' => [
            ':input[name="layout[enabled]"]' => ['checked' => FALSE],
          ],
        ],
      ];
      if (!$is_enabled) {
        $form['layout']['allow_custom']['#attributes']['disabled'] = 'disabled';
      }


  /** * {@inheritdoc} */
  public function getContext($entity_type_id = NULL) {
    if (!$entity_type_id) {
      throw new \LogicException('Missing entity type ID');
    }

    $display = $this->getDisplay($entity_type_id);
    return ($display && $display->isOverridable()) ? '1' : '0';
  }

  /** * {@inheritdoc} */
  public function getCacheableMetadata($entity_type_id = NULL) {
    if (!$entity_type_id) {
      throw new \LogicException('Missing entity type ID');
    }

    $cacheable_metadata = new CacheableMetadata();
    
$this->assertSame($expected$actual);
  }

  /** * @covers ::getContext * @covers ::getDisplay * * @dataProvider providerTestGetContext */
  public function testGetContext($is_overridden$expected) {
    $entity_display = $this->prophesize(LayoutEntityDisplayInterface::class);
    $entity_display->isOverridable()->willReturn($is_overridden);

    $entity_type_id = 'a_fieldable_entity_type';
    $fieldable_entity = $this->prophesize(FieldableEntityInterface::class);
    $fieldable_entity->getEntityTypeId()->willReturn($entity_type_id);
    $fieldable_entity->bundle()->willReturn('the_bundle_id');

    $route_match = $this->prophesize(RouteMatchInterface::class);
    $route_match->getParameter($entity_type_id)->willReturn($fieldable_entity->reveal());

    // \Drupal\Core\Entity\Entity\EntityViewDisplay::collectRenderDisplay() is a     // static method and can not be mocked on its own. All of the expectations
// Access is always denied on non-default translations.     return $result->andIf(AccessResult::allowedIf(!($entity instanceof TranslatableInterface && !$entity->isDefaultTranslation())))->addCacheableDependency($entity);
  }

  /** * {@inheritdoc} */
  public function isApplicable(RefinableCacheableDependencyInterface $cacheability) {
    $default_section_storage = $this->getDefaultSectionStorage();
    $cacheability->addCacheableDependency($default_section_storage)->addCacheableDependency($this);
    // Check that overrides are enabled and have at least one section.     return $default_section_storage->isOverridable() && $this->isOverridden();
  }

  /** * {@inheritdoc} */
  public function isOverridden() {
    // If there are any sections at all, including a blank one, this section     // storage has been overridden. Do not use count() as it does not include     // blank sections.     return !empty($this->getSections());
  }

}
$this->setThirdPartySetting('layout_builder', 'sections', array_values($sections));
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    $original_value = isset($this->original) ? $this->original->isOverridable() : FALSE;
    $new_value = $this->isOverridable();
    if ($original_value !== $new_value) {
      $entity_type_id = $this->getTargetEntityTypeId();
      $bundle = $this->getTargetBundle();

      if ($new_value) {
        $this->addSectionField($entity_type_id$bundle, OverridesSectionStorage::FIELD_NAME);
      }
      else {
        $this->removeSectionField($entity_type_id$bundle, OverridesSectionStorage::FIELD_NAME);
      }
    }
Home | Imprint | This part of the site doesn't use cookies.