class ExampleWithDependencyInjection in Extra Field 8.2
Same name and namespace in other branches
- 8 modules/extra_field_example/src/Plugin/ExtraField/Display/ExampleWithDependencyInjection.php \Drupal\extra_field_example\Plugin\ExtraField\Display\ExampleWithDependencyInjection
 
Example Extra field Display.
Plugin annotation
@ExtraFieldDisplay(
  id = "article_only",
  label = @Translation("Dependency Injection example"),
  description = @Translation("An extra field that uses dependency injection."),
  bundles = {
    "node.article",
  }
)
  Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\extra_field\Plugin\ExtraFieldDisplayBase implements ExtraFieldDisplayInterface
- class \Drupal\extra_field_example\Plugin\ExtraField\Display\ExampleWithDependencyInjection implements ContainerFactoryPluginInterface uses StringTranslationTrait
 
 
 - class \Drupal\extra_field\Plugin\ExtraFieldDisplayBase implements ExtraFieldDisplayInterface
 
Expanded class hierarchy of ExampleWithDependencyInjection
File
- modules/
extra_field_example/ src/ Plugin/ ExtraField/ Display/ ExampleWithDependencyInjection.php, line 24  
Namespace
Drupal\extra_field_example\Plugin\ExtraField\DisplayView source
class ExampleWithDependencyInjection extends ExtraFieldDisplayBase implements ContainerFactoryPluginInterface {
  use StringTranslationTrait;
  /**
   * The current request object.
   *
   * @var \Symfony\Component\HttpFoundation\Request
   */
  protected $currentRequest;
  /**
   * Constructs a ExtraFieldDisplayFormattedBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->currentRequest = $request_stack
      ->getCurrentRequest();
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('request_stack'));
  }
  /**
   * {@inheritdoc}
   */
  public function view(ContentEntityInterface $entity) {
    // Some output to demonstrate the injected service.
    $scheme = $this->currentRequest
      ->getScheme();
    return [
      '#markup' => $this
        ->t('Request scheme: @scheme', [
        '@scheme' => $scheme,
      ]),
    ];
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            ExampleWithDependencyInjection:: | 
                  protected | property | The current request object. | |
| 
            ExampleWithDependencyInjection:: | 
                  public static | function | 
            Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: | 
                  |
| 
            ExampleWithDependencyInjection:: | 
                  public | function | 
            Builds a renderable array for the field. Overrides ExtraFieldDisplayInterface:: | 
                  |
| 
            ExampleWithDependencyInjection:: | 
                  public | function | 
            Constructs a ExtraFieldDisplayFormattedBase object. Overrides PluginBase:: | 
                  |
| 
            ExtraFieldDisplayBase:: | 
                  protected | property | The field's parent entity. | |
| 
            ExtraFieldDisplayBase:: | 
                  protected | property | The entity view display. | |
| 
            ExtraFieldDisplayBase:: | 
                  protected | property | The view mode the entity is rendered in. | |
| 
            ExtraFieldDisplayBase:: | 
                  public | function | 
            Returns the field's parent entity. Overrides ExtraFieldDisplayInterface:: | 
                  |
| 
            ExtraFieldDisplayBase:: | 
                  public | function | 
            Returns the entity view display object of the field's host entity. Overrides ExtraFieldDisplayInterface:: | 
                  |
| 
            ExtraFieldDisplayBase:: | 
                  public | function | 
            Returns the entity view mode object of the field's host entity. Overrides ExtraFieldDisplayInterface:: | 
                  |
| 
            ExtraFieldDisplayBase:: | 
                  public | function | 
            Stores the field's parent entity. Overrides ExtraFieldDisplayInterface:: | 
                  |
| 
            ExtraFieldDisplayBase:: | 
                  public | function | 
            Stores the entity view display. Overrides ExtraFieldDisplayInterface:: | 
                  |
| 
            ExtraFieldDisplayBase:: | 
                  public | function | 
            Stores the entity view mode. Overrides ExtraFieldDisplayInterface:: | 
                  |
| 
            PluginBase:: | 
                  protected | property | Configuration information passed into the plugin. | 1 | 
| 
            PluginBase:: | 
                  protected | property | The plugin implementation definition. | 1 | 
| 
            PluginBase:: | 
                  protected | property | The plugin_id. | |
| 
            PluginBase:: | 
                  constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
| 
            PluginBase:: | 
                  public | function | 
            Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: | 
                  |
| 
            PluginBase:: | 
                  public | function | 
            Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: | 
                  |
| 
            PluginBase:: | 
                  public | function | 
            Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: | 
                  3 | 
| 
            PluginBase:: | 
                  public | function | 
            Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: | 
                  |
| 
            PluginBase:: | 
                  public | function | Determines if the plugin is configurable. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. |