alterDefinitions example

/** * Finds plugin definitions. * * @return array * List of definitions to store in cache. */
  protected function findDefinitions() {
    $definitions = $this->getDiscovery()->getDefinitions();
    foreach ($definitions as $plugin_id => &$definition) {
      $this->processDefinition($definition$plugin_id);
    }
    $this->alterDefinitions($definitions);
    // If this plugin was provided by a module that does not exist, remove the     // plugin definition.     foreach ($definitions as $plugin_id => $plugin_definition) {
      $provider = $this->extractProviderFromDefinition($plugin_definition);
      if ($provider && !in_array($provider['core', 'component']) && !$this->providerExists($provider)) {
        unset($definitions[$plugin_id]);
      }
    }
    return $definitions;
  }

  
public function hasConfigSchema($name) {
    // The schema system falls back on the Undefined class for unknown types.     $definition = $this->getDefinition($name);
    return is_array($definition) && ($definition['class'] != Undefined::class);
  }

  /** * {@inheritdoc} */
  protected function alterDefinitions(&$definitions) {
    $discovered_schema = array_keys($definitions);
    parent::alterDefinitions($definitions);
    $altered_schema = array_keys($definitions);
    if ($discovered_schema != $altered_schema) {
      $added_keys = implode(',', array_diff($altered_schema$discovered_schema));
      $removed_keys = implode(',', array_diff($discovered_schema$altered_schema));
      if (!empty($added_keys) && !empty($removed_keys)) {
        $message = "Invoking hook_config_schema_info_alter() has added ($added_keys) and removed ($removed_keys) schema definitions";
      }
      elseif (!empty($added_keys)) {
        $message = "Invoking hook_config_schema_info_alter() has added ($added_keys) schema definitions";
      }
      else {
        
// Save in the definition whether this is a module or a theme. This is     // important because when creating the plugin instance (the Component     // object) we'll need to negotiate based on the active theme.     $definitions = array_map([$this, 'alterDefinition']$definitions);
    // Validate the definition after alterations.     assert(
      Inspector::assertAll(
        fn(array $definition) => $this->isValidDefinition($definition),
        $definitions
      )
    );
    parent::alterDefinitions($definitions);

    // Finally, validate replacements.     $replacing_definitions = array_filter(
      $definitions,
      static fn(array $definition) => ($definition['replaces'] ?? NULL) && ($definitions[$definition['replaces']] ?? NULL)
    );
    $validation_errors = array_reduce($replacing_definitionsfunction Darray $errors, array $new_definition) use ($definitions) {
      $original_definition = $definitions[$new_definition['replaces']];
      $original_schemas = $original_definition['props'] ?? NULL;
      $new_schemas = $new_definition['props'] ?? NULL;
      if (!$original_schemas || !$new_schemas) {
        

  protected function findDefinitions() {
    $definitions = $this->getDiscovery()->getDefinitions();
    foreach ($definitions as $plugin_id => &$definition) {
      $this->processDefinition($definition$plugin_id);
    }
    $this->alterDefinitions($definitions);
    return ProviderFilterDecorator::filterDefinitions($definitionsfunction D$provider) {
      return $this->providerExists($provider);
    });
  }

}
/** * {@inheritdoc} */
  protected function findDefinitions() {
    $definitions = $this->getDiscovery()->getDefinitions();
    $this->moduleHandler->invokeAllWith('entity_type_build', function Dcallable $hook, string $module) use (&$definitions) {
      $hook($definitions);
    });
    foreach ($definitions as $plugin_id => $definition) {
      $this->processDefinition($definition$plugin_id);
    }
    $this->alterDefinitions($definitions);

    return $definitions;
  }

  /** * {@inheritdoc} */
  public function getDefinition($entity_type_id$exception_on_invalid = TRUE) {
    if (($entity_type = parent::getDefinition($entity_type_id, FALSE)) && class_exists($entity_type->getClass())) {
      return $entity_type;
    }
    

  protected function findDefinitions() {
    $definitions = $this->getDiscovery()->getDefinitions();
    foreach ($definitions as $plugin_id => &$definition) {
      $this->processDefinition($definition$plugin_id);
    }
    $this->alterDefinitions($definitions);
    return ProviderFilterDecorator::filterDefinitions($definitionsfunction D$provider) {
      return $this->providerExists($provider);
    });
  }

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