You are here

class EntityTypeInfo in Webform Analysis 8

Same name in this branch
  1. 8 src/EntityTypeInfo.php \Drupal\webform_analysis\EntityTypeInfo
  2. 8 modules/webform_node_analysis/src/EntityTypeInfo.php \Drupal\webform_node_analysis\EntityTypeInfo

Manipulates entity type information.

This class contains primarily bridged hooks for compile-time or cache-clear-time hooks. Runtime hooks should be placed in EntityOperations.

Hierarchy

Expanded class hierarchy of EntityTypeInfo

1 file declares its use of EntityTypeInfo
webform_node_analysis.module in modules/webform_node_analysis/webform_node_analysis.module
Webform Analysis - Module.

File

modules/webform_node_analysis/src/EntityTypeInfo.php, line 17

Namespace

Drupal\webform_node_analysis
View source
class EntityTypeInfo implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * EntityTypeInfo constructor.
   *
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   Current user.
   */
  public function __construct(AccountInterface $current_user) {
    $this->currentUser = $current_user;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('current_user'));
  }

  /**
   * Adds devel links to appropriate entity types.
   *
   * This is an alter hook bridge.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
   *   The master entity type list to alter.
   *
   * @see hook_entity_type_alter()
   */
  public function entityTypeAlter(array &$entity_types) {
    $entity_types['node']
      ->setFormClass('webform_analysis', 'Drupal\\webform_analysis\\Form\\WebformAnalysisForm');
    $entity_types['node']
      ->setLinkTemplate('webform.results_analysis', '/node/{node}/webform/results/analysis');
  }

  /**
   * Adds devel operations on entity that supports it.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity on which to define an operation.
   *
   * @return array
   *   An array of operation definitions.
   *
   * @see hook_entity_operation()
   */
  public function entityOperation(EntityInterface $entity) {
    $operations = [];
    if ($this->currentUser
      ->hasPermission('view any webform submission')) {
      if ($entity
        ->bundle() === 'webform' && $entity
        ->hasLinkTemplate('webform.results_analysis')) {
        $operations['analysis'] = [
          'title' => $this
            ->t('Analysis'),
          'weight' => 100,
          'url' => $entity
            ->toUrl('webform.results_analysis'),
        ];
      }
    }
    return $operations;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityTypeInfo::$currentUser protected property The current user.
EntityTypeInfo::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
EntityTypeInfo::entityOperation public function Adds devel operations on entity that supports it.
EntityTypeInfo::entityTypeAlter public function Adds devel links to appropriate entity types.
EntityTypeInfo::__construct public function EntityTypeInfo constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.