class TestFieldApplicableFormatter

Same name and namespace in other branches
  1. 11.x core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldApplicableFormatter
  2. 10 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldApplicableFormatter
  3. 9 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldApplicableFormatter

Plugin implementation of the 'field_test_applicable' formatter.

It is applicable to test_field fields unless their name is 'deny_applicable'.

Plugin annotation


@FieldFormatter(
  id = "field_test_applicable",
  label = @Translation("Applicable"),
  description = @Translation("Applicable formatter"),
  field_types = {
    "test_field"
  },
  weight = 15,
)

Hierarchy

Expanded class hierarchy of TestFieldApplicableFormatter

File

core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php, line 24

Namespace

Drupal\field_test\Plugin\Field\FieldFormatter
View source
class TestFieldApplicableFormatter extends FormatterBase {
  
  /**
   * {@inheritdoc}
   */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    return $field_definition->getName() != 'deny_applicable';
  }
  
  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    return [
      '#markup' => 'Nothing to see here',
    ];
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.