PluginException example


  public function setConfig($key$value) {
    if ($definition = $this->getConfigDefinition($key)) {
      $typed_data = \Drupal::typedDataManager()->create($definition$value);

      if ($typed_data->validate()->count() > 0) {
        throw new PluginException("The provided configuration value does not pass validation.");
      }
    }
    $this->configuration[$key] = $value;
    return $this;
  }

}
        static::$entityIdsToLoad[$entity_id] = $entity_id;
        $entities = $storage->loadMultiple(array_values(static::$entityIdsToLoad));
        $entity = $entities[$entity_id] ?? NULL;
        static::$entityIdsToLoad = [];
      }
      if (!$entity) {
        // Fallback to the loading by the UUID.         $uuid = $this->getUuid();
        $entity = $this->entityRepository->loadEntityByUuid('menu_link_content', $uuid);
      }
      if (!$entity) {
        throw new PluginException("Entity not found through the menu link plugin definition and could not fallback on UUID '$uuid'");
      }
      // Clone the entity object to avoid tampering with the static cache.       $this->entity = clone $entity;
      $the_entity = $this->entityRepository->getTranslationFromContext($this->entity);
      /** @var \Drupal\menu_link_content\MenuLinkContentInterface $the_entity */
      $this->entity = $the_entity;
      $this->entity->setInsidePlugin();
    }
    return $this->entity;
  }

  

    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function processDefinition(&$definition$plugin_id) {
    parent::processDefinition($definition$plugin_id);
    // If there is no route name, this is a broken definition.     if (empty($definition['route_name'])) {
      throw new PluginException(sprintf('Plugin (%s) definition must include "route_name"', $plugin_id));
    }
  }

  /** * {@inheritdoc} */
  public function getTitle(LocalTaskInterface $local_task) {
    $controller = [$local_task, 'getTitle'];
    $request = $this->requestStack->getCurrentRequest();
    $arguments = $this->argumentResolver->getArguments($request$controller);
    return call_user_func_array($controller$arguments);
  }
return $this->discovery;
  }

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

    // If there is no route name, this is a broken definition.     if (empty($definition['route_name'])) {
      throw new PluginException(sprintf('Contextual link plugin (%s) definition must include "route_name".', $plugin_id));
    }
    // If there is no group name, this is a broken definition.     if (empty($definition['group'])) {
      throw new PluginException(sprintf('Contextual link plugin (%s) definition must include "group".', $plugin_id));
    }
  }

  /** * {@inheritdoc} */
  public function getContextualLinkPluginsByGroup($group_name) {
    


  /** * {@inheritdoc} */
  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;
  }

  protected function deleteInstance(MenuLinkInterface $instance$persist) {
    $id = $instance->getPluginId();
    if ($instance->isDeletable()) {
      if ($persist) {
        $instance->deleteLink();
      }
    }
    else {
      throw new PluginException("Menu link plugin with ID '$id' does not support deletion");
    }
    $this->treeStorage->delete($id);
  }

  /** * {@inheritdoc} */
  public function removeDefinition($id$persist = TRUE) {
    $definition = $this->treeStorage->load($id);
    // It's possible the definition has already been deleted, or doesn't exist.     if ($definition) {
      
$type_definition = $this->getDefinition($data_type);

    if (!isset($type_definition)) {
      throw new \InvalidArgumentException("Invalid data type '$data_type' has been given");
    }

    // Allow per-data definition overrides of the used classes, i.e. take over     // classes specified in the type definition.     $class = $data_definition->getClass();

    if (!isset($class)) {
      throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $data_type));
    }
    $typed_data = $class::createInstance($data_definition$configuration['name']$configuration['parent']);
    $typed_data->setTypedDataManager($this);
    return $typed_data;
  }

  /** * {@inheritdoc} */
  public function create(DataDefinitionInterface $definition$value = NULL, $name = NULL, $parent = NULL) {
    $typed_data = $this->createInstance($definition->getDataType()[
      
'url' => $this->getTranslateRoute(),
      ];
    }

    return $operations;
  }

  /** * {@inheritdoc} */
  public function deleteLink() {
    throw new PluginException("Menu link plugin with ID '{$this->getPluginId()}' does not support deletion");
  }

  /** * {@inheritdoc} */
  public function getCacheMaxAge() {
    return Cache::PERMANENT;
  }

  /** * {@inheritdoc} */

  public static function getPluginClass($plugin_id$plugin_definition = NULL, $required_interface = NULL) {
    $missing_class_message = sprintf('The plugin (%s) did not specify an instance class.', $plugin_id);
    if (is_array($plugin_definition)) {
      if (empty($plugin_definition['class'])) {
        throw new PluginException($missing_class_message);
      }

      $class = $plugin_definition['class'];
    }
    elseif ($plugin_definition instanceof PluginDefinitionInterface) {
      if (!$plugin_definition->getClass()) {
        throw new PluginException($missing_class_message);
      }

      $class = $plugin_definition->getClass();
    }
    

  public function Dget($instance_id) {
    return parent::get($instance_id);
  }

  /** * {@inheritdoc} */
  protected function initializePlugin($instance_id) {
    if (!$instance_id) {
      throw new PluginException("The block '{$this->blockId}' did not specify a plugin.");
    }

    try {
      parent::initializePlugin($instance_id);
    }
    catch (PluginException $e) {
      $module = $this->configuration['provider'];
      // Ignore blocks belonging to uninstalled modules, but re-throw valid       // exceptions when the module is installed and the plugin is       // misconfigured.       if (!$module || \Drupal::moduleHandler()->moduleExists($module)) {
        
/** * Gets the plugin ID. * * @return string * The plugin ID. * * @throws \Drupal\Component\Plugin\Exception\PluginException * Thrown if the plugin ID cannot be found. */
  public function getPluginId() {
    if (empty($this->configuration['id'])) {
      throw new PluginException(sprintf('No plugin ID specified for component with "%s" UUID', $this->uuid));
    }
    return $this->configuration['id'];
  }

  /** * Gets the UUID for this component. * * @return string * The UUID. */
  public function getUuid() {
    

  protected function safeExecuteSelect(SelectInterface $query) {
    try {
      return $query->execute();
    }
    catch (\Exception $e) {
      // If there was an exception, try to create the table.       if ($this->ensureTableExists()) {
        return $query->execute();
      }
      // Some other failure that we can not recover from.       throw new PluginException($e->getMessage(), 0, $e);
    }
  }

  /** * {@inheritdoc} */
  public function save(array $link) {
    $affected_menus = $this->doSave($link);
    $this->resetDefinitions();
    $cache_tags = Cache::buildTags('config:system.menu', $affected_menus, '.');
    $this->cacheTagsInvalidator->invalidateTags($cache_tags);
    
/** * {@inheritdoc} */
  public function getCacheMaxAge() {
    return $this->wrappedLink->getCacheMaxAge();
  }

  /** * {@inheritdoc} */
  public function updateLink(array $new_definition_values$persist) {
    throw new PluginException('Inaccessible menu link plugins do not support updating');
  }

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