loadOverrideFree example

protected function getEntityForm(MenuInterface $menu) {
    $entity_form = $this->entityTypeManager->getFormObject('menu', 'edit');
    $entity_form->setEntity($menu);
    return $entity_form;
  }

  /** * {@inheritdoc} */
  public function setPlugin(PluginInspectionInterface $plugin) {
    $this->plugin = $plugin;
    $this->menu = $this->menuStorage->loadOverrideFree($this->plugin->getDerivativeId());
  }

  /** * Determines if the menu has configuration overrides. * * @return bool * TRUE if the menu has configuration overrides, otherwise FALSE. */
  protected function hasMenuOverrides() {
    // @todo Replace the following with $this->menu->hasOverrides() in https://www.drupal.org/project/drupal/issues/2910353     // and remove this function.
// Prime the cache prior to adding a config override.     $storage->load($this->entityId);

    // Add the config override, and ensure that what is loaded is correct     // despite the prior cache priming.     \Drupal::configFactory()->addOverride(new ConfigOverrider());
    $entity_override = $storage->load($this->entityId);
    $this->assertSame('Overridden label', $entity_override->label);

    // Load override free to ensure that loading the config entity again does     // not return the overridden value.     $entity_no_override = $storage->loadOverrideFree($this->entityId);
    $this->assertNotSame('Overridden label', $entity_no_override->label);
    $this->assertNotSame($entity_override->_loadStamp, $entity_no_override->_loadStamp);

    // Reload the entity and ensure the cache is used.     $this->assertSame($entity_no_override->_loadStamp, $storage->loadOverrideFree($this->entityId)->_loadStamp);

    // Enable overrides and reload the entity and ensure the cache is used.     $this->assertSame($entity_override->_loadStamp, $storage->load($this->entityId)->_loadStamp);
  }

}
// If the entity type is dynamic, confirm it to be a config entity. Static     // entity types will have performed this check in self::applies().     if (str_starts_with($definition['type'], 'entity:{')) {
      $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
      if (!$entity_type->entityClassImplements(ConfigEntityInterface::class)) {
        return parent::convert($value$definition$name$defaults);
      }
    }

    if ($storage = $this->entityTypeManager->getStorage($entity_type_id)) {
      // Make sure no overrides are loaded.       return $storage->loadOverrideFree($value);
    }
  }

  /** * {@inheritdoc} */
  public function applies($definition$name, Route $route) {
    if (isset($definition['with_config_overrides']) && $definition['with_config_overrides']) {
      return FALSE;
    }

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