handlePluginNotFound example

/** * {@inheritdoc} */
  public function createInstance($plugin_id, array $configuration = []) {
    // If this PluginManager has fallback capabilities catch     // PluginNotFoundExceptions.     if ($this instanceof FallbackPluginManagerInterface) {
      try {
        return $this->getFactory()->createInstance($plugin_id$configuration);
      }
      catch (PluginNotFoundException $e) {
        return $this->handlePluginNotFound($plugin_id$configuration);
      }
    }
    else {
      return $this->getFactory()->createInstance($plugin_id$configuration);
    }
  }

  /** * Allows plugin managers to specify custom behavior if a plugin is not found. * * @param string $plugin_id * The ID of the missing requested plugin. * @param array $configuration * An array of configuration relevant to the plugin instance. * * @return object * A fallback plugin instance. * * @throws \BadMethodCallException * When ::getFallbackPluginId() is not implemented in the concrete plugin * manager class. */

  public function getFallbackPluginId($plugin_id, array $configuration = []) {
    return 'broken';
  }

  /** * {@inheritdoc} */
  protected function handlePluginNotFound($plugin_id, array $configuration) {
    $this->logger->warning('The "%plugin_id" was not found', ['%plugin_id' => $plugin_id]);
    return parent::handlePluginNotFound($plugin_id$configuration);
  }

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