InvalidPluginDefinitionException example

/** * {@inheritdoc} */
  public function createInstance(PluginWithFormsInterface $plugin$operation$fallback_operation = NULL) {
    if (!$plugin->hasFormClass($operation)) {
      // Use the default form class if no form is specified for this operation.       if ($fallback_operation && $plugin->hasFormClass($fallback_operation)) {
        $operation = $fallback_operation;
      }
      else {
        throw new InvalidPluginDefinitionException($plugin->getPluginId()sprintf('The "%s" plugin did not specify a "%s" form class', $plugin->getPluginId()$operation));
      }
    }

    $form_class = $plugin->getFormClass($operation);

    // If the form specified is the plugin itself, use it directly.     if (ltrim(get_class($plugin), '\\') === ltrim($form_class, '\\')) {
      $form_object = $plugin;
    }
    else {
      $form_object = $this->classResolver->getInstanceFromDefinition($form_class);
    }
$discovery = new ContainerDerivativeDiscoveryDecorator($discovery);
      $this->discovery = $discovery;
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function processDefinition(&$definition$plugin_id) {
    if (!$definition instanceof CKEditor5PluginDefinition) {
      throw new InvalidPluginDefinitionException($plugin_idsprintf('The "%s" CKEditor 5 plugin definition must extend %s', $plugin_id, CKEditor5PluginDefinition::class));
    }

    // A derived plugin will still have the ID of the derivative, rather than     // that of the derived plugin ID (`<base plugin ID>:<derivative ID>`).     // Generate an updated CKEditor5PluginDefinition.     // @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::encodePluginId()     // @todo Remove this in https://www.drupal.org/project/drupal/issues/2458769.     $is_derived = $definition->id() !== $plugin_id;
    if ($is_derived) {
      $definition = new CKEditor5PluginDefinition(['id' => $plugin_id] + $definition->toArray());
    }

    
return $mappers;
  }

  /** * {@inheritdoc} */
  public function processDefinition(&$definition$plugin_id) {
    parent::processDefinition($definition$plugin_id);

    if (!isset($definition['base_route_name'])) {
      throw new InvalidPluginDefinitionException($plugin_id, "The plugin definition of the mapper '$plugin_id' does not contain a base_route_name.");
    }
  }

  /** * {@inheritdoc} */
  public function buildDataDefinition(array $definition$value = NULL, $name = NULL, $parent = NULL) {
    return $this->typedConfigManager->buildDataDefinition($definition$value$name$parent);
  }

  /** * {@inheritdoc} */

  public function getMigrationDependencies(bool $expand = FALSE) {
    if (!$expand) {
      @trigger_error('Calling Migration::getMigrationDependencies() without expanding the plugin IDs is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. In most cases, use getMigrationDependencies(TRUE). See https://www.drupal.org/node/3266691', E_USER_DEPRECATED);
    }
    // @todo Before Drupal 11.0.0, remove ::set() and these checks.     // @see https://www.drupal.org/project/drupal/issues/3262395     $this->migration_dependencies = ($this->migration_dependencies ?: []) + ['required' => [], 'optional' => []];
    if (count($this->migration_dependencies) !== 2 || !is_array($this->migration_dependencies['required']) || !is_array($this->migration_dependencies['optional'])) {
      throw new InvalidPluginDefinitionException($this->id(), "Invalid migration dependencies configuration for migration {$this->id()}");
    }
    $this->migration_dependencies['optional'] = array_unique(array_merge($this->migration_dependencies['optional']$this->findMigrationDependencies($this->process)));
    if (!$expand) {
      return $this->migration_dependencies;
    }
    return array_map(
      [$this->migrationPluginManager, 'expandPluginIds'],
      $this->migration_dependencies
    );
  }

  
/** * Run the node_migration_no_migrate_drupal test migration. * * @return array * A renderable array. */
  public function execute() {
    $migration_plugin_manager = \Drupal::service('plugin.manager.migration');
    $definitions = $migration_plugin_manager->getDefinitions();
    if ($definitions['node_migration_no_migrate_drupal']['label'] !== 'Node Migration No Migrate Drupal') {
      throw new InvalidPluginDefinitionException('node_migration_no_migrate_drupal');
    }
    $migrations = $migration_plugin_manager->createInstances('');
    $result = (new MigrateExecutable($migrations['node_migration_no_migrate_drupal']))->import();
    if ($result !== MigrationInterface::RESULT_COMPLETED) {
      throw new \RuntimeException('Migration failed');
    }

    return [
      '#type' => 'markup',
      '#markup' => 'Migration was successful.',
    ];
  }
protected $defaultConfiguration = [
    'bundle' => NULL,
    'include_translations' => TRUE,
    'add_revision_id' => TRUE,
  ];

  /** * {@inheritdoc} */
  public function __construct(array $configuration$plugin_id$plugin_definition, MigrationInterface $migration, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
    if (empty($plugin_definition['entity_type'])) {
      throw new InvalidPluginDefinitionException($plugin_id, 'Missing required "entity_type" definition.');
    }
    $this->entityTypeManager = $entity_type_manager;
    $this->entityFieldManager = $entity_field_manager;
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
    $this->entityType = $this->entityTypeManager->getDefinition($plugin_definition['entity_type']);
    if (!$this->entityType instanceof ContentEntityTypeInterface) {
      throw new InvalidPluginDefinitionException($plugin_idsprintf('The entity type (%s) is not supported. The "content_entity" source plugin only supports content entities.', $plugin_definition['entity_type']));
    }
    if (!empty($configuration['bundle'])) {
      if (!$this->entityType->hasKey('bundle')) {
        throw new \InvalidArgumentException(sprintf('A bundle was provided but the entity type (%s) is not bundleable.', $plugin_definition['entity_type']));
      }

  public static function validateCKEditor5Aspects(string $id, array $definition): void {
    if (!isset($definition['ckeditor5'])) {
      throw new InvalidPluginDefinitionException($idsprintf('The "%s" CKEditor 5 plugin definition must contain a "ckeditor5" key.', $id));
    }

    if (!isset($definition['ckeditor5']['plugins'])) {
      throw new InvalidPluginDefinitionException($idsprintf('The "%s" CKEditor 5 plugin definition must contain a "ckeditor5.plugins" key.', $id));
    }

    // Automatic link decorators make sense in CKEditor 5, where the generated     // HTML must be assumed to be served as-is. But it does not make sense in     // in Drupal, where we prefer not storing (hardcoding) such decisions in the     // database. Drupal instead filters it on output, using the filter system.     if (isset($definition['ckeditor5']['config']['link'])) {
      
// If the argument is required throw an exception.           throw new \InvalidArgumentException("Argument '$id' expected by plugin '{$this->getPluginId()}' but not passed");
        }
      }
      else {
        // Optional arguments require a 'default' value.         // We check this even if the argument is provided by the caller, as we         // want to fail fast here, i.e. at development time.         if (!array_key_exists('default', $argument)) {
          // The plugin did not define a default, so throw a plugin exception,           // not an invalid argument exception.           throw new InvalidPluginDefinitionException("Default for argument '$id' expected by plugin '{$this->getPluginId()}' but not defined");
        }

        // Use the default value if the argument is not passed in.         if (!array_key_exists($id$arguments)) {
          $arguments[$id] = $argument['default'];
        }
      }
    }
    return $arguments;
  }

  

  public function getListBuilder($entity_type_id) {
    return $this->getHandler($entity_type_id, 'list_builder');
  }

  /** * {@inheritdoc} */
  public function getFormObject($entity_type_id$operation) {
    if (!$class = $this->getDefinition($entity_type_id, TRUE)->getFormClass($operation)) {
      throw new InvalidPluginDefinitionException($entity_type_idsprintf('The "%s" entity type did not specify a "%s" form class.', $entity_type_id$operation));
    }

    $form_object = $this->classResolver->getInstanceFromDefinition($class);

    return $form_object
      ->setStringTranslation($this->stringTranslation)
      ->setModuleHandler($this->moduleHandler)
      ->setEntityTypeManager($this)
      ->setOperation($operation);
  }

  

    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function processDefinition(&$definition$plugin_id) {
    parent::processDefinition($definition$plugin_id);

    if (!$definition instanceof LayoutDefinition) {
      throw new InvalidPluginDefinitionException($plugin_idsprintf('The "%s" layout definition must extend %s', $plugin_id, LayoutDefinition::class));
    }

    // Add the module or theme path to the 'path'.     $provider = $definition->getProvider();
    if ($this->moduleHandler->moduleExists($provider)) {
      $base_path = $this->moduleHandler->getModule($provider)->getPath();
    }
    elseif ($this->themeHandler->themeExists($provider)) {
      $base_path = $this->themeHandler->getTheme($provider)->getPath();
    }
    else {
      
return $data;
  }

  /** * Tests the convert() method with an invalid entity type ID. * * @covers ::convert */
  public function testConvertWithInvalidEntityType() {
    $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager->getStorage('invalid_entity_type_id')->willThrow(new InvalidPluginDefinitionException('invalid_entity_type_id'));
    $entity_repository = $this->prophesize(EntityRepositoryInterface::class);
    $converter = new EntityRevisionParamConverter($entity_type_manager->reveal()$entity_repository->reveal());

    $this->expectException(InvalidPluginDefinitionException::class);
    $converter->convert('valid_id', ['type' => 'entity_revision:invalid_entity_type_id'], 'foo', ['foo' => 'valid_id']);
  }

  /** * Tests the convert() method with an invalid dynamic entity type ID. * * @covers ::convert */
Home | Imprint | This part of the site doesn't use cookies.