You are here

class Entity in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  2. 8 modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  3. 8.2 modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  4. 8.3 modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  5. 8.4 modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  6. 8.5 modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  7. 8.7 modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  8. 8.8 modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  9. 10.3.x modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  10. 10.0.x modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  11. 10.1.x modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity
  12. 10.2.x modules/custom/mentions/src/Plugin/Mentions/Entity.php \Drupal\mentions\Plugin\Mentions\Entity

Class Entity.

Plugin annotation


@Mention(
 id = "entity",
 name = @Translation("Entity")
)

Hierarchy

Expanded class hierarchy of Entity

2 string references to 'Entity'
field.field.activity.activity.field_activity_entity.yml in modules/custom/activity_creator/config/install/field.field.activity.activity.field_activity_entity.yml
modules/custom/activity_creator/config/install/field.field.activity.activity.field_activity_entity.yml
field.field.activity.activity.field_activity_entity.yml in modules/social_features/social_activity/config/install/field.field.activity.activity.field_activity_entity.yml
modules/social_features/social_activity/config/install/field.field.activity.activity.field_activity_entity.yml

File

modules/custom/mentions/src/Plugin/Mentions/Entity.php, line 22

Namespace

Drupal\mentions\Plugin\Mentions
View source
class Entity implements MentionsPluginInterface {
  private $tokenService;
  private $entityManager;
  private $entityQueryService;

  /**
   * Entity constructor.
   */
  public function __construct(Token $token, EntityManager $entity_manager, QueryFactory $entity_query) {
    $this->tokenService = $token;
    $this->entityManager = $entity_manager;
    $this->entityQueryService = $entity_query;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $token = $container
      ->get('token');
    $entity_manager = $container
      ->get('entity.manager');
    $entity_query = $container
      ->get('entity.query');
    return new static($token, $entity_manager, $entity_query);
  }

  /**
   * {@inheritdoc}
   */
  public function outputCallback($mention, $settings) {
    $entity = $this->entityManager
      ->getStorage($mention['target']['entity_type'])
      ->load($mention['target']['entity_id']);
    $output['value'] = $this->tokenService
      ->replace($settings['value'], [
      $mention['target']['entity_type'] => $entity,
    ]);
    if ($settings['renderlink']) {
      $output['link'] = $this->tokenService
        ->replace($settings['rendertextbox'], [
        $mention['target']['entity_type'] => $entity,
      ]);
    }
    return $output;
  }

  /**
   * {@inheritdoc}
   */
  public function targetCallback($value, $settings) {
    $entity_type = $settings['entity_type'];
    $input_value = $settings['value'];
    $query = $this->entityQueryService
      ->get($entity_type);
    $result = $query
      ->condition($input_value, $value)
      ->execute();
    if (!empty($result)) {
      $result = reset($result);
      $target['entity_type'] = $entity_type;
      $target['entity_id'] = $result;
      return $target;
    }
    else {
      return FALSE;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function mentionPresaveCallback(EntityInterface $entity) {
  }

  /**
   * {@inheritdoc}
   */
  public function patternCallback($settings, $regex) {
  }

  /**
   * {@inheritdoc}
   */
  public function settingsCallback(FormInterface $form, FormStateInterface $form_state, $type) {
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSubmitCallback(FormInterface $form, FormStateInterface $form_state, $type) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entity::$entityManager private property
Entity::$entityQueryService private property
Entity::$tokenService private property
Entity::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
Entity::mentionPresaveCallback public function The mentionPresaveCallback function. Overrides MentionsPluginInterface::mentionPresaveCallback
Entity::outputCallback public function The outputCallback function. Overrides MentionsPluginInterface::outputCallback
Entity::patternCallback public function The patternCallback function. Overrides MentionsPluginInterface::patternCallback
Entity::settingsCallback public function The settingsCallback function. Overrides MentionsPluginInterface::settingsCallback
Entity::settingsSubmitCallback public function The settingsSubmitCallback function. Overrides MentionsPluginInterface::settingsSubmitCallback
Entity::targetCallback public function The targetCallback function. Overrides MentionsPluginInterface::targetCallback
Entity::__construct public function Entity constructor.