Completed
Pull Request — 8.x-1.x (#123)
by
unknown
02:27
created

EntityLabel::isApplicable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * Contains \Drupal\entity_browser\Plugin\EntityBrowser\FieldWidgetDisplay\EntityLabel.
5
 */
6
7
namespace Drupal\entity_browser\Plugin\EntityBrowser\FieldWidgetDisplay;
8
9
use Drupal\Core\Entity\EntityInterface;
10
use Drupal\Core\Entity\EntityTypeInterface;
11
use Drupal\Core\Form\FormStateInterface;
12
use Drupal\Core\Plugin\PluginBase;
13
use Drupal\entity_browser\FieldWidgetDisplayInterface;
14
15
/**
16
 * Displays a label of the entity.
17
 *
18
 * @EntityBrowserFieldWidgetDisplay(
19
 *   id = "label",
20
 *   label = @Translation("Entity label"),
21
 *   description = @Translation("Displays entity with a label.")
22
 * )
23
 */
24
class EntityLabel extends PluginBase implements FieldWidgetDisplayInterface {
25
26
  /**
27
   * {@inheritdoc}
28
   */
29
  public function view(EntityInterface $entity) {
30
    return $entity->label();
31
  }
32
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function settingsForm(array $form, FormStateInterface $form_state) {
37
    return [];
38
  }
39
40
  /**
41
   * {@inheritdoc}
42
   */
43
  public function isApplicable(EntityTypeInterface $entity_type) {
44
    return TRUE;
45
  }
46
47
}
48