Version 1
[yaffs-website] / web / core / modules / field / tests / modules / field_test / src / Plugin / Field / FieldFormatter / TestFieldApplicableFormatter.php
diff --git a/web/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php b/web/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php
new file mode 100644 (file)
index 0000000..418b4c6
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace Drupal\field_test\Plugin\Field\FieldFormatter;
+use Drupal\Core\Field\FieldDefinitionInterface;
+use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Field\FormatterBase;
+
+
+/**
+ * Plugin implementation of the 'field_test_applicable' formatter.
+ *
+ * It is applicable to test_field fields unless their name is 'deny_applicable'.
+ *
+ * @FieldFormatter(
+ *   id = "field_test_applicable",
+ *   label = @Translation("Applicable"),
+ *   description = @Translation("Applicable formatter"),
+ *   field_types = {
+ *     "test_field"
+ *   },
+ *   weight = 15,
+ * )
+ */
+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'];
+  }
+
+}