diff --git a/field_permission_example/field_permission_example.module b/field_permission_example/field_permission_example.module index 0cd7d84..3063594 100644 --- a/field_permission_example/field_permission_example.module +++ b/field_permission_example/field_permission_example.module @@ -37,8 +37,9 @@ * * How does it work? * - * You can install this module and go to path /examples/field_permission_example - * for an introduction on how to use this field. + * You can install this module and go to path + * /examples/field_permission_example for an introduction on how to use this + * field. * * OK, how does the code work? * @@ -133,9 +134,10 @@ function field_permission_example_entity_field_access($operation, FieldDefinitio return AccessResult::allowed(); } - // At this point, we need to know if the user "owns" the entity we're attached to. - // If it's a user, we'll use the account name to test. Otherwise rely on the entity implementing the - // the EntityOwnerInterface. Anything else can't be owned, and we'll refuse access. + // At this point, we need to know if the user "owns" the entity we're + // attached to. If it's a user, we'll use the account name to test. + // Otherwise rely on the entity implementing the EntityOwnerInterface. + // Anything else can't be owned, and we'll refuse access. if ($items) { $entity = $items->getEntity(); if ((($entity instanceof EntityOwnerInterface) and @@ -161,9 +163,9 @@ function field_permission_example_entity_field_access($operation, FieldDefinitio /** * Implements hook_ENTITY_TYPE_access(). * - * Note: this routine is added so we can more easily test our access code. Core - * defines an entity_test entity that is used for testing fields in core. We add - * this routine to make the entity_test entity editable by our tests. + * Note: this routine is added so we can more easily test our access code. + * Core defines an entity_test entity that is used for testing fields in core. + * We add this routine to make the entity_test entity editable by our tests. */ function field_permission_example_entity_test_access(EntityInterface $entity, $operation, AccountInterface $account, $langcode) { if ($operation == 'edit') { diff --git a/field_permission_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php b/field_permission_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php index 3e737d8..9d712eb 100644 --- a/field_permission_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php +++ b/field_permission_example/src/Plugin/Field/FieldFormatter/SimpleTextFormatter.php @@ -11,7 +11,7 @@ use Drupal\Core\Field\FormatterBase; use Drupal\Core\Field\FieldItemListInterface; /** - * Plugin implementation of the 'field_permission_example_simple_text' formatter. + * Plugin implementation of our "sticky-note" formatter. * * @FieldFormatter( * id = "field_permission_example_simple_formatter", @@ -35,7 +35,7 @@ class SimpleTextFormatter extends FormatterBase { // We wrap the fieldnote content up in a div tag. '#type' => 'html_tag', '#tag' => 'div', - // This text is auto-XSS escaped. See docs for @RenderElement("html_tag"). + // This text is auto-XSS escaped. See docs for the html_tag element. '#value' => $item->value, // Let's give the note a nice sticky-note CSS appearance. '#attributes' => array( diff --git a/field_permission_example/src/Tests/FieldNoteItemTest.php b/field_permission_example/src/Tests/FieldNoteItemTest.php index 84e13ba..7e4686a 100644 --- a/field_permission_example/src/Tests/FieldNoteItemTest.php +++ b/field_permission_example/src/Tests/FieldNoteItemTest.php @@ -32,8 +32,10 @@ class FieldNoteItemTest extends FieldUnitTestBase { protected function setUp() { array_unshift(self::$modules, 'field_permission_example'); parent::setUp(); - // Tests for SimpleTest do not support standard Drupal dependency - // injection, so use the KernelTest class' supplied container. + // Tests for SimpleTest cannot usefully implement + // ContainerInjectionInterface the way PHPUnit tests do. + // We instead use KernelTest class' supplied container + // to get services we require. $type_manager = $this->container->get('entity_type.manager'); // Set up our entity_type and user type for our new field: @@ -85,8 +87,8 @@ class FieldNoteItemTest extends FieldUnitTestBase { 'bundle' => 'user', ])->save(); - // Fetch a form display for a user. - // Most likely, this will already exist, so check as Core does. + // Fetch a form display for a user. Most likely, this will already + // exist, so check as Core does. // @see https://api.drupal.org/api/drupal/core%21includes%21entity.inc/function/entity_get_form_display/8 $entity_form_display = $type_manager diff --git a/field_permission_example/templates/description.html.twig b/field_permission_example/templates/description.html.twig index df673a1..1df2bc8 100644 --- a/field_permission_example/templates/description.html.twig +++ b/field_permission_example/templates/description.html.twig @@ -9,7 +9,7 @@ #}
The Field Permission Example module shows how you can restrict view and edit permissions within your field implementation. It adds a new field type called Fieldnote. Fieldnotes appear as simple text boxes on the create/edit form, and as sticky notes when viewed. @@ -24,5 +24,5 @@ trying to resolve for the current field/user combination.
Definitely look through the code to see various implementation details.
- +{% endtrans %}