PluginNotFoundException example


    private function getBundle(string $bundleName): BundleInterface
    {
        try {
            $bundle = $this->kernel->getBundle($bundleName);
        } catch (\InvalidArgumentException) {
            $bundle = $this->pluginLoader->getPluginInstances()->get($bundleName);
        }

        if ($bundle === null) {
            throw new PluginNotFoundException($bundleName);
        }

        return $bundle;
    }

    /** * @return array<BundleInterface> */
    private function getAdditionalBundles(Plugin $bundle): array
    {
        $params = new AdditionalBundleParameters(
            

    }
    $this->treeStorage->rebuild($definitions);
  }

  /** * {@inheritdoc} */
  public function getDefinition($plugin_id$exception_on_invalid = TRUE) {
    $definition = $this->treeStorage->load($plugin_id);
    if (empty($definition) && $exception_on_invalid) {
      throw new PluginNotFoundException($plugin_id);
    }
    return $definition;
  }

  /** * {@inheritdoc} */
  public function hasDefinition($plugin_id) {
    return (bool) $this->getDefinition($plugin_id, FALSE);
  }

  
/** * {@inheritdoc} */
  protected function mapFromStorageRecords(array $records) {
    foreach ($records as $id => &$record) {
      try {
        $class = $this->fieldTypeManager->getPluginClass($record['type']);
      }
      catch (PluginNotFoundException $e) {
        $config_id = $this->getPrefix() . $id;
        throw new PluginNotFoundException($record['type'], "Unable to determine class for field type '{$record['type']}' found in the '$config_id' configuration", $e->getCode()$e);
      }
      $record['settings'] = $class::storageSettingsFromConfigData($record['settings']);
    }
    return parent::mapFromStorageRecords($records);
  }

  /** * {@inheritdoc} */
  protected function mapToStorageRecord(EntityInterface $entity) {
    $record = parent::mapToStorageRecord($entity);
    

  public function lookup($migration_id, array $source_id_values) {
    $results = [];
    $migrations = $this->migrationPluginManager->createInstances($migration_id);
    if (!$migrations) {
      if (is_array($migration_id)) {
        if (count($migration_id) != 1) {
          throw new PluginException("Plugin IDs '" . implode("', '", $migration_id) . "' were not found.");
        }
        $migration_id = reset($migration_id);
      }
      throw new PluginNotFoundException($migration_id);
    }
    foreach ($migrations as $migration) {
      if ($result = $this->doLookup($migration$source_id_values)) {
        $results = array_merge($results$result);
      }
    }
    return $results;
  }

  /** * Performs a lookup. * * @param \Drupal\migrate\Plugin\MigrationInterface $migration * The migration upon which to perform the lookup. * @param array $source_id_values * The source ID values to look up. * * @return array * An array of arrays of destination identifier values. * * @throws \Drupal\migrate\MigrateException * Thrown when $source_id_values contains unknown keys, or the wrong number * of keys. */
use ProphecyTrait;

  /** * A callback method for mocking FactoryInterface objects. */
  public function createInstanceCallback() {
    $args = func_get_args();
    $plugin_id = $args[0];
    $configuration = $args[1];
    if ('invalid' == $plugin_id) {
      throw new PluginNotFoundException($plugin_id);
    }
    return [
      'plugin_id' => $plugin_id,
      'configuration' => $configuration,
    ];
  }

  /** * Generates a mocked FactoryInterface object with known properties. */
  public function getMockFactoryInterface($expects_count) {
    
$this->entityTypeManager->getDefinition(Argument::cetera())
      ->will(function D$args) use ($definitions) {
        $entity_type_id = $args[0];
        $exception_on_invalid = $args[1];
        if (isset($definitions[$entity_type_id])) {
          return $definitions[$entity_type_id];
        }
        elseif (!$exception_on_invalid) {
          return NULL;
        }
        else {
          throw new PluginNotFoundException($entity_type_id);
        }
      });
    $this->entityTypeManager->getDefinitions()->willReturn($definitions);
  }

  /** * @covers ::onFieldDefinitionCreate */
  public function testOnFieldDefinitionCreateNewField() {
    $field_definition = $this->prophesize(FieldDefinitionInterface::class);
    $field_definition->getTargetEntityTypeId()->willReturn('test_entity_type');
    

  public function createStub($migration_id, array $source_ids, array $default_values = []$key_by_destination_ids = NULL) {
    $migrations = $this->migrationPluginManager->createInstances([$migration_id]);
    if (!$migrations) {
      throw new PluginNotFoundException($migration_id);
    }
    if (count($migrations) !== 1) {
      throw new \LogicException(sprintf('Cannot stub derivable migration "%s". You must specify the id of a specific derivative to stub.', $migration_id));
    }
    $migration = reset($migrations);
    $source_id_keys = array_keys($migration->getSourcePlugin()->getIds());
    if (count($source_id_keys) !== count($source_ids)) {
      throw new \InvalidArgumentException('Expected and provided source id counts do not match.');
    }
    if (array_keys($source_ids) === range(0, count($source_ids) - 1)) {
      $source_ids = array_combine($source_id_keys$source_ids);
    }
/** * {@inheritdoc} */
  protected function mapFromStorageRecords(array $records) {
    foreach ($records as $id => &$record) {
      try {
        $class = $this->fieldTypeManager->getPluginClass($record['field_type']);
      }
      catch (PluginNotFoundException $e) {
        $config_id = $this->getPrefix() . $id;
        throw new PluginNotFoundException($record['field_type'], "Unable to determine class for field type '{$record['field_type']}' found in the '$config_id' configuration", $e->getCode()$e);
      }
      $record['settings'] = $class::fieldSettingsFromConfigData($record['settings']);
    }
    return parent::mapFromStorageRecords($records);
  }

  /** * {@inheritdoc} */
  protected function mapToStorageRecord(EntityInterface $entity) {
    $record = parent::mapToStorageRecord($entity);
    
// Store the original order of the instance IDs for export.       $this->originalOrder = $this->instanceIds;
    }
  }

  /** * {@inheritdoc} */
  protected function initializePlugin($instance_id) {
    $configuration = $this->configurations[$instance_id] ?? [];
    if (!isset($configuration[$this->pluginKey])) {
      throw new PluginNotFoundException($instance_id);
    }
    $this->set($instance_id$this->manager->createInstance($configuration[$this->pluginKey]$configuration));
  }

  /** * Sorts all plugin instances in this collection. * * @return $this */
  public function sort() {
    uasort($this->instanceIds, [$this, 'sortHelper']);
    
      // always be mocked.       $entity_type->getLinkTemplates()->willReturn([]);

      $definitions[$key] = $entity_type->reveal();
    }

    $this->entityTypeManager->getDefinition(Argument::type('string'))
      ->will(function D$args) use ($definitions) {
        if (isset($definitions[$args[0]])) {
          return $definitions[$args[0]];
        }
        throw new PluginNotFoundException($args[0]);
      });
    $this->entityTypeManager->getDefinition(Argument::type('string'), FALSE)
      ->will(function D$args) use ($definitions) {
        if (isset($definitions[$args[0]])) {
          return $definitions[$args[0]];
        }
      });
    $this->entityTypeManager->getDefinitions()->willReturn($definitions);

  }

  

  protected function doGetDefinition(array $definitions$plugin_id$exception_on_invalid) {
    // Avoid using a ternary that would create a copy of the array.     if (isset($definitions[$plugin_id])) {
      return $definitions[$plugin_id];
    }
    elseif (!$exception_on_invalid) {
      return NULL;
    }

    $valid_ids = implode(', ', array_keys($definitions));
    throw new PluginNotFoundException($plugin_idsprintf('The "%s" plugin does not exist. Valid plugin IDs for %s are: %s', $plugin_idstatic::class$valid_ids));
  }

  /** * {@inheritdoc} */
  public function hasDefinition($plugin_id) {
    return (bool) $this->getDefinition($plugin_id, FALSE);
  }

}
if ($method) {
      $this->fieldPlugin->$method($this->row->reveal())->willReturn($expected_value);
    }
    $plugin = new ProcessField(['method' => $method]$value[]$this->fieldManager->reveal()$this->migration->reveal());

    if ($migrate_exception) {
      $this->expectException(MigrateException::class);
      $this->expectExceptionMessage($migrate_exception);
    }

    if ($plugin_not_found) {
      $exception = new PluginNotFoundException('foo');
      $this->fieldManager->getPluginIdFromFieldType()->willThrow($exception);
    }

    $transformed_value = $plugin->transform($value$this->migrateExecutable->reveal()$this->row->reveal(), 'foo');
    $this->assertSame($transformed_value$expected_value);
  }

  /** * Provides data for the transform method test. * * @return array * - The method to call. * - The value to process. * - The expected transformed value. * - The MigrateException message to expect. * - Whether the field plugin is not found. */
/** * {@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;
    }
    elseif (!$exception_on_invalid) {
      return NULL;
    }

    throw new PluginNotFoundException($entity_type_idsprintf('The "%s" entity type does not exist.', $entity_type_id));
  }

  /** * Gets the active definition for a content entity type. * * @param string $entity_type_id * The entity type ID. * * @return \Drupal\Core\Entity\EntityTypeInterface * The active entity type definition. * * @internal */
/** * @throws PluginNotFoundException */
    public function getPluginByName(string $pluginName, Context $context): PluginEntity
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('name', $pluginName));

        $pluginEntity = $this->getPlugins($criteria$context)->first();
        if ($pluginEntity === null) {
            throw new PluginNotFoundException($pluginName);
        }

        return $pluginEntity;
    }

    private function getPlugins(Criteria $criteria, Context $context): PluginCollection
    {
        /** @var PluginCollection $pluginCollection */
        $pluginCollection = $this->pluginRepo->search($criteria$context)->getEntities();

        return $pluginCollection;
    }
$this->entityTypeManager->getDefinition(Argument::cetera())
      ->will(function D$args) use ($definitions) {
        $entity_type_id = $args[0];
        $exception_on_invalid = $args[1];
        if (isset($definitions[$entity_type_id])) {
          return $definitions[$entity_type_id];
        }
        elseif (!$exception_on_invalid) {
          return NULL;
        }
        else {
          throw new PluginNotFoundException($entity_type_id);
        }
      });
    $this->entityTypeManager->getDefinitions()->willReturn($definitions);

  }

  /** * Tests the clearCachedBundles() method. * * @covers ::clearCachedBundles */
  
Home | Imprint | This part of the site doesn't use cookies.