You are here

public static function FieldPermissionsService::isCommentField in Field Permissions 8

Same name and namespace in other branches
  1. 8.2 src/FieldPermissionsService.php \Drupal\field_permissions\FieldPermissionsService::isCommentField()

Field is attached to comment entity.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: Fields to get permissions.

Return value

bool TRUE if in a comment entity.

Overrides FieldPermissionsServiceInterface::isCommentField

3 calls to FieldPermissionsService::isCommentField()
FieldPermissionsService::getFieldAccess in src/FieldPermissionsService.php
Get access for field by operations and account permisisons.
FieldPermissionsService::hasFieldViewAccessForEveryEntity in src/FieldPermissionsService.php
Determines if the given account may view the field, regardless of entity.
field_permissions_form_field_config_edit_form_alter in ./field_permissions.module
Implements hook_form_FORM_ID_alter().

File

src/FieldPermissionsService.php, line 145

Class

FieldPermissionsService
The field permission service.

Namespace

Drupal\field_permissions

Code

public static function isCommentField(FieldDefinitionInterface $field_definition) {
  if (!\Drupal::hasService('comment.manager')) {

    // Comment module isn't enabled.
    return FALSE;
  }
  $field_name = $field_definition
    ->getName();
  $field_names = \Drupal::service('comment.manager')
    ->getFields($field_definition
    ->getTargetEntityTypeId());

  // Comment field.
  if (in_array($field_name, array_keys($field_names))) {
    return TRUE;
  }
  return FALSE;
}