loadOverride example


  public function getDescription() {
    return (string) $this->pluginDefinition['description'];
  }

  /** * {@inheritdoc} */
  public function isResettable() {
    // The link can be reset if it has an override.     return (bool) $this->staticOverride->loadOverride($this->getPluginId());
  }

  /** * {@inheritdoc} */
  public function getResetRoute(): Url {
    return Url::fromRoute('menu_ui.link_reset', ['menu_link_plugin' => $this->getPluginId()]);
  }

  /** * {@inheritdoc} */

  public function testLoadOverride($overrides$id$expected) {
    $config_factory = $this->getConfigFactoryStub(['core.menu.static_menu_link_overrides' => ['definitions' => $overrides]]);
    $static_override = new StaticMenuLinkOverrides($config_factory);

    $this->assertEquals($expected$static_override->loadOverride($id));
  }

  /** * Provides test data for testLoadOverride. */
  public function providerTestLoadOverride() {
    $data = [];
    // Valid ID.     $data[] = [['test1' => ['parent' => 'test0']], 'test1', ['parent' => 'test0']];
    // Non existing ID.     $data[] = [['test1' => ['parent' => 'test0']], 'test2', []];
    
if ($definition) {
      // Cast keys to avoid config schema during save.       $definition['menu_name'] = (string) $definition['menu_name'];
      $definition['parent'] = (string) $definition['parent'];
      $definition['weight'] = (int) $definition['weight'];
      $definition['expanded'] = (bool) $definition['expanded'];
      $definition['enabled'] = (bool) $definition['enabled'];

      $id = static::encodeId($id);
      $all_overrides = $this->getConfig()->get('definitions');
      // Combine with any existing data.       $all_overrides[$id] = $definition + $this->loadOverride($id);
      $this->getConfig()->set('definitions', $all_overrides)->save(TRUE);
    }
    return array_keys($definition);
  }

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

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