diff -u b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php --- b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php @@ -80,7 +80,7 @@ $info = array( '#theme' => 'field', '#title' => $this->field_definition['label'], - '#access' => field_access('view', $this->field_definition, $entity->entityType(), $entity), + '#access' => $this->checkFieldAccess('view', $entity), '#label_display' => $this->label, '#view_mode' => $this->viewMode, '#language' => $langcode, @@ -121,2 +121,16 @@ + /** + * Returns whether the currently logged in user has access to the field. + * + * @todo Remove this once Field API access is unified with entity field + * access: http://drupal.org/node/1994140. + */ + protected function checkFieldAccess($op, $entity) { + if ($field = field_info_field($this->field_definition['field_name'])) { + return field_access($op, $field, $entity->entityType(), $entity); + } + else { + return FALSE; + } + } } diff -u b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php --- b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -145,7 +145,7 @@ // when $langcode is unknown. '#language' => $langcode, $langcode => $elements, - '#access' => field_access('edit', $this->field_definition, $entity->entityType(), $entity), + '#access' => $this->checkFieldAccess('edit', $entity), ); return $addition; @@ -422,2 +422,17 @@ + /** + * Returns whether the currently logged in user has access to the field. + * + * @todo Remove this once Field API access is unified with entity field + * access: http://drupal.org/node/1994140. + */ + protected function checkFieldAccess($op, $entity) { + if ($field = field_info_field($this->field_definition['field_name'])) { + return field_access($op, $field, $entity->entityType(), $entity); + } + else { + return FALSE; + } + } + }