You are here

class MiconStaticMenuLinkOverrides in Micon 8

Same name and namespace in other branches
  1. 2.x micon_menu/src/MiconStaticMenuLinkOverrides.php \Drupal\micon_menu\MiconStaticMenuLinkOverrides

Defines an implementation of the menu link override using a config file.

Hierarchy

Expanded class hierarchy of MiconStaticMenuLinkOverrides

File

micon_menu/src/MiconStaticMenuLinkOverrides.php, line 10

Namespace

Drupal\micon_menu
View source
class MiconStaticMenuLinkOverrides extends StaticMenuLinkOverrides {

  /**
   * {@inheritdoc}
   */
  public function saveOverride($id, array $definition) {

    // Only allow to override a specific subset of the keys.
    $expected = [
      'menu_name' => '',
      'parent' => '',
      'weight' => 0,
      'expanded' => FALSE,
      'enabled' => FALSE,
      // Micon: options are allowed.
      'options' => [],
    ];

    // Filter the overrides to only those that are expected.
    $definition = array_intersect_key($definition, $expected);

    // Ensure all values are set.
    $definition = $definition + $expected;
    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'];

      // Micon: options are allowed.
      $definition['options'] = $definition['options'];
      $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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MiconStaticMenuLinkOverrides::saveOverride public function Saves the override. Overrides StaticMenuLinkOverrides::saveOverride
StaticMenuLinkOverrides::$config protected property The menu link overrides config object.
StaticMenuLinkOverrides::$configFactory protected property The config factory object.
StaticMenuLinkOverrides::$configName protected property The config name used to store the overrides.
StaticMenuLinkOverrides::deleteMultipleOverrides public function Deletes multiple overrides to definitions of static (YAML-defined) links. Overrides StaticMenuLinkOverridesInterface::deleteMultipleOverrides
StaticMenuLinkOverrides::deleteOverride public function Deletes any overrides to the definition of a static (YAML-defined) link. Overrides StaticMenuLinkOverridesInterface::deleteOverride
StaticMenuLinkOverrides::encodeId protected static function Encodes the ID by replacing dots with double underscores.
StaticMenuLinkOverrides::getCacheTags public function The unique cache tag associated with this menu link override. Overrides StaticMenuLinkOverridesInterface::getCacheTags
StaticMenuLinkOverrides::getConfig protected function Gets the configuration object when needed.
StaticMenuLinkOverrides::loadMultipleOverrides public function Loads overrides to multiple definitions of a static (YAML-defined) link. Overrides StaticMenuLinkOverridesInterface::loadMultipleOverrides
StaticMenuLinkOverrides::loadOverride public function Loads any overrides to the definition of a static (YAML-defined) link. Overrides StaticMenuLinkOverridesInterface::loadOverride
StaticMenuLinkOverrides::reload public function Reloads the overrides from config. Overrides StaticMenuLinkOverridesInterface::reload
StaticMenuLinkOverrides::__construct public function Constructs a StaticMenuLinkOverrides object.