isOverridden example

->setOverridable()
      ->save();

    $entity = EntityTest::create();
    $entity->set(OverridesSectionStorage::FIELD_NAME, [new Section('layout_onecol')]);
    $entity->save();
    $entity = EntityTest::load($entity->id());

    $context = EntityContext::fromEntity($entity);
    $this->plugin->setContext('entity', $context);

    $this->assertTrue($this->plugin->isOverridden());
    $this->plugin->removeSection(0);
    $this->assertTrue($this->plugin->isOverridden());
    $this->plugin->removeAllSections(TRUE);
    $this->assertTrue($this->plugin->isOverridden());
    $this->plugin->removeAllSections();
    $this->assertFalse($this->plugin->isOverridden());
  }

}
// 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());
  }

}

  public function onPrepareLayout(PrepareLayoutEvent $event) {
    $section_storage = $event->getSectionStorage();

    // If the layout has pending changes, add a warning.     if ($this->layoutTempstoreRepository->has($section_storage)) {
      $this->messenger->addWarning($this->t('You have unsaved changes.'));
    }
    else {
      // If the layout is an override that has not yet been overridden, copy the       // sections from the corresponding default.       if ($section_storage instanceof OverridesSectionStorageInterface && !$section_storage->isOverridden()) {
        $sections = $section_storage->getDefaultSectionStorage()->getSections();
        foreach ($sections as $section) {
          $section_storage->appendSection($section);
        }
      }
      // Add storage to tempstore regardless of what the storage is.       $this->layoutTempstoreRepository->set($section_storage);
    }
  }

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