You are here

class PluginWrapper in RESTful 7.2

Hierarchy

Expanded class hierarchy of PluginWrapper

1 file declares its use of PluginWrapper
DataProviderPlug.php in src/Plugin/resource/DataProvider/DataProviderPlug.php
Contains \Drupal\restful\Plugin\resource\DataProvider\DataProviderPlug.

File

src/Plugin/resource/DataInterpreter/PluginWrapper.php, line 13
Contains \Drupal\restful\Plugin\resource\DataInterpreter\PluginWrapper.

Namespace

Drupal\restful\Plugin\resource\DataInterpreter
View source
class PluginWrapper implements PluginWrapperInterface {

  /**
   * Plugin configuration.
   *
   * @var array
   */
  protected $pluginConfiguration = array();

  /**
   * Plugin definition.
   *
   * @var array
   */
  protected $pluginDefinition = array();

  /**
   * Plugin instance.
   *
   * @var PluginInspectionInterface
   */
  protected $plugin;

  /**
   * Constructs a PluginWrapper object.
   *
   * @param PluginInspectionInterface $plugin
   *   The plugin to wrap.
   */
  public function __construct(PluginInspectionInterface $plugin) {
    $this->plugin = $plugin;
    $this->pluginDefinition = $plugin
      ->getPluginDefinition();

    // For configurable plugins, expose those properties as well.
    if ($plugin instanceof ConfigurablePluginInterface) {
      $this->pluginConfiguration = $plugin
        ->getConfiguration();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function get($key) {

    // If there is a key by that name in the plugin configuration return it, if
    // not then check the plugin definition. If it cannot be found, return NULL.
    $value = isset($this->pluginConfiguration[$key]) ? $this->pluginConfiguration[$key] : NULL;
    return $value ? $value : (isset($this->pluginDefinition[$key]) ? $this->pluginDefinition[$key] : NULL);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginWrapper::$plugin protected property Plugin instance.
PluginWrapper::$pluginConfiguration protected property Plugin configuration.
PluginWrapper::$pluginDefinition protected property Plugin definition.
PluginWrapper::get public function Gets a field from the plugin configuration. Overrides PluginWrapperInterface::get
PluginWrapper::__construct public function Constructs a PluginWrapper object.