Commit 6e5d1a09 authored by catch's avatar catch

Issue #1874300 by Berdir, swentel: Remove $entity_type argument from...

Issue #1874300 by Berdir, swentel: Remove $entity_type argument from field.module functions that receive a single $entity.
parent c4c45acc
......@@ -487,7 +487,7 @@ function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_st
// Copy field values to the entity.
if ($info['fieldable']) {
field_attach_submit($entity_type, $entity, $form, $form_state);
field_attach_submit($entity, $form, $form_state);
}
}
......
......@@ -653,7 +653,7 @@ protected function invokeHook($hook, EntityInterface $entity) {
$function = 'field_attach_delete_revision';
}
if (!empty($this->entityInfo['fieldable']) && function_exists($function)) {
$function($this->entityType, $entity);
$function($entity);
}
// Invoke the hook.
module_invoke_all($this->entityType . '_' . $hook, $entity);
......
......@@ -275,7 +275,7 @@ protected function invokeHook($hook, EntityInterface $entity) {
$function = 'field_attach_delete_revision';
}
if (!empty($this->entityInfo['fieldable']) && function_exists($function)) {
$function($this->entityType, $entity->getBCEntity());
$function($entity->getBCEntity());
}
// Invoke the hook.
......
......@@ -78,7 +78,7 @@ public function form(array $form, array &$form_state, EntityInterface $entity) {
// entity properties.
$info = $entity->entityInfo();
if (!empty($info['fieldable'])) {
field_attach_form($entity->entityType(), $entity, $form, $form_state, $this->getFormLangcode($form_state));
field_attach_form($entity, $form, $form_state, $this->getFormLangcode($form_state));
}
return $form;
}
......@@ -160,7 +160,7 @@ public function validate(array $form, array &$form_state) {
$info = $entity->entityInfo();
if (!empty($info['fieldable'])) {
field_attach_form_validate($entity->entityType(), $entity, $form, $form_state);
field_attach_form_validate($entity, $form, $form_state);
}
// @todo Remove this.
......
......@@ -23,7 +23,7 @@ public function form(array $form, array &$form_state, EntityInterface $entity) {
// entity properties.
$info = $entity->entityInfo();
if (!empty($info['fieldable'])) {
field_attach_form($entity->entityType(), $entity->getBCEntity(), $form, $form_state, $this->getFormLangcode($form_state));
field_attach_form($entity->getBCEntity(), $form, $form_state, $this->getFormLangcode($form_state));
}
return $form;
}
......@@ -38,7 +38,7 @@ public function validate(array $form, array &$form_state) {
$info = $entity->entityInfo();
if (!empty($info['fieldable'])) {
field_attach_form_validate($entity->entityType(), $entity->getBCEntity(), $form, $form_state);
field_attach_form_validate($entity->getBCEntity(), $form, $form_state);
}
// @todo Remove this.
......@@ -78,7 +78,7 @@ public function buildEntity(array $form, array &$form_state) {
// Copy field values to the entity.
if ($info['fieldable']) {
field_attach_submit($entity_type, $entity->getBCEntity(), $form, $form_state);
field_attach_submit($entity->getBCEntity(), $form, $form_state);
}
return $entity;
}
......
......@@ -72,7 +72,7 @@ public function buildContent(array $entities = array(), $view_mode = 'full', $la
module_invoke_all('entity_prepare_view', $view_mode_entities, $this->entityType);
foreach ($view_mode_entities as $entity) {
$entity->content += field_attach_view($this->entityType, $entity, $displays[$view_mode][$entity->bundle()], $langcode);
$entity->content += field_attach_view($entity, $displays[$view_mode][$entity->bundle()], $langcode);
}
}
}
......
......@@ -110,7 +110,7 @@ function comment_admin_overview($form, &$form_state, $arg) {
// Remove the first node title from the node_titles array and attach to
// the comment.
$comment->node_title = array_shift($node_titles);
$comment_body = field_get_items('comment', $comment, 'comment_body');
$comment_body = field_get_items($comment, 'comment_body');
$options[$comment->cid] = array(
'subject' => array(
'data' => array(
......
......@@ -1539,7 +1539,7 @@ function comment_preview(Comment $comment) {
$preview_build = array();
if (!form_get_errors()) {
$comment_body = field_get_items('comment', $comment, 'comment_body');
$comment_body = field_get_items($comment, 'comment_body');
$comment->format = $comment_body[0]['format'];
// Attach the user and time information.
if (!empty($comment->name)) {
......@@ -1665,7 +1665,7 @@ function template_preprocess_comment(&$variables) {
}
// Preprocess fields.
field_attach_preprocess('comment', $comment, $variables['elements'], $variables);
field_attach_preprocess($comment, $variables['elements'], $variables);
// Helpful $content variable for templates.
foreach (element_children($variables['elements']) as $key) {
......
......@@ -155,9 +155,9 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
break;
case 'body':
if ($items = field_get_items('comment', $comment, 'comment_body', $langcode)) {
if ($items = field_get_items($comment, 'comment_body', $langcode)) {
$instance = field_info_instance('comment', 'body', 'comment_body');
$field_langcode = field_language('comment', $comment, 'comment_body', $langcode);
$field_langcode = field_language($comment, 'comment_body', $langcode);
$replacements[$original] = $sanitize ? _text_sanitize($instance, $field_langcode, $items[0], 'value') : $items[0]['value'];
}
break;
......
......@@ -95,7 +95,7 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
// The form submission took care of saving the updated entity. Return the
// updated view of the field.
$entity = $form_state['entity'];
$output = field_view_field($entity->entityType(), $entity, $field_name, $view_mode, $langcode);
$output = field_view_field($entity, $field_name, $view_mode, $langcode);
$response->addCommand(new FieldFormSavedCommand(drupal_render($output)));
}
......@@ -135,7 +135,7 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
public function getUntransformedText(EntityInterface $entity, $field_name, $langcode, $view_mode) {
$response = new AjaxResponse();
$output = field_view_field($entity->entityType(), $entity, $field_name, $view_mode, $langcode);
$output = field_view_field($entity, $field_name, $view_mode, $langcode);
$langcode = $output['#language'];
// Direct text editing is only supported for single-valued fields.
$editable_text = check_markup($output['#items'][0]['value'], $output['#items'][0]['format'], $langcode, FALSE, array(FILTER_TYPE_TRANSFORM_REVERSIBLE, FILTER_TYPE_TRANSFORM_IRREVERSIBLE));
......
......@@ -23,7 +23,7 @@ public function build(array $form, array &$form_state, EntityInterface $entity,
}
// Add the field form.
field_attach_form($form_state['entity']->entityType(), $form_state['entity'], $form, $form_state, $form_state['langcode'], array('field_name' => $form_state['field_name']));
field_attach_form($form_state['entity'], $form, $form_state, $form_state['langcode'], array('field_name' => $form_state['field_name']));
// Add a submit button. Give it a class for easy JavaScript targeting.
$form['actions'] = array('#type' => 'actions');
......@@ -63,7 +63,7 @@ protected function init(array &$form_state, EntityInterface $entity, $field_name
*/
public function validate(array $form, array &$form_state) {
$entity = $this->buildEntity($form, $form_state);
field_attach_form_validate($entity->entityType(), $entity, $form, $form_state, array('field_name' => $form_state['field_name']));
field_attach_form_validate($entity, $form, $form_state, array('field_name' => $form_state['field_name']));
}
/**
......@@ -86,7 +86,7 @@ protected function buildEntity(array $form, array &$form_state) {
// @todo field_attach_submit() only "submits" to the in-memory $entity
// object, not to anywhere persistent. Consider renaming it to minimize
// confusion: http://drupal.org/node/1846648.
field_attach_submit($entity->entityType(), $entity, $form, $form_state, array('field_name' => $form_state['field_name']));
field_attach_submit($entity, $form, $form_state, array('field_name' => $form_state['field_name']));
// @todo Refine automated log messages and abstract them to all entity
// types: http://drupal.org/node/1678002.
......
......@@ -89,7 +89,7 @@ function testEmailField() {
// Verify that a mailto link is displayed.
$entity = field_test_entity_test_load($id);
$display = entity_get_display($entity->entityType(), $entity->bundle(), 'full');
$entity->content = field_attach_view('test_entity', $entity, $display);
$entity->content = field_attach_view($entity, $display);
$this->drupalSetContent(drupal_render($entity->content));
$this->assertLinkByHref('mailto:test@example.com');
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -5,6 +5,7 @@
* Field CRUD API, handling field and field instance creation and deletion.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\FieldException;
/**
......@@ -883,7 +884,7 @@ function field_purge_batch($batch_size) {
field_attach_load($entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1));
foreach ($entities as $entity) {
// Purge the data for the entity.
field_purge_data($entity_type, $entity, $field, $instance);
field_purge_data($entity, $field, $instance);
}
}
else {
......@@ -909,28 +910,26 @@ function field_purge_batch($batch_size) {
* a single field. The entity itself is not being deleted, and it is quite
* possible that other field data will remain attached to it.
*
* @param $entity_type
* The type of $entity; e.g. 'node' or 'user'.
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The pseudo-entity whose field data is being purged.
* @param $field
* The (possibly deleted) field whose data is being purged.
* @param $instance
* The deleted field instance whose data is being purged.
*/
function field_purge_data($entity_type, $entity, $field, $instance) {
function field_purge_data(EntityInterface $entity, $field, $instance) {
// Each field type's hook_field_delete() only expects to operate on a single
// field at a time, so we can use it as-is for purging.
$options = array('field_id' => $instance['field_id'], 'deleted' => TRUE);
_field_invoke('delete', $entity_type, $entity, $dummy, $dummy, $options);
_field_invoke('delete', $entity, $dummy, $dummy, $options);
// Tell the field storage system to purge the data.
module_invoke($field['storage']['module'], 'field_storage_purge', $entity_type, $entity, $field, $instance);
module_invoke($field['storage']['module'], 'field_storage_purge', $entity, $field, $instance);
// Let other modules act on purging the data.
foreach (module_implements('field_attach_purge') as $module) {
$function = $module . '_field_attach_purge';
$function($entity_type, $entity, $field, $instance);
$function($entity, $field, $instance);
}
}
......
<?php
use Drupal\Core\Entity\EntityInterface;
/**
* @file
* Default 'implementations' of hook_field_*(): common field housekeeping.
......@@ -18,9 +20,7 @@
*
* @see _hook_field_validate()
*
* @param $entity_type
* The type of $entity.
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity for the operation.
* @param $field
* The field structure for the operation.
......@@ -38,7 +38,7 @@
* - error: An error code (should be a string, prefixed with the module name).
* - message: The human readable message to be displayed.
*/
function field_default_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
function field_default_validate(EntityInterface $entity, $field, $instance, $langcode, $items, &$errors) {
// Filter out empty values.
$items = _field_filter_items($field, $items);
......@@ -60,9 +60,7 @@ function field_default_validate($entity_type, $entity, $field, $instance, $langc
* the current user doesn't have 'edit' permission for the field. This is the
* default field 'insert' operation.
*
* @param $entity_type
* The type of $entity.
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity for the operation.
* @param $field
* The field structure for the operation.
......@@ -73,7 +71,7 @@ function field_default_validate($entity_type, $entity, $field, $instance, $langc
* @param $items
* An array that this function will populate with default values.
*/
function field_default_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
function field_default_insert(EntityInterface $entity, $field, $instance, $langcode, &$items) {
// _field_invoke() populates $items with an empty array if the $entity has no
// entry for the field, so we check on the $entity itself.
// We also check that the current field translation is actually defined before
......@@ -82,16 +80,14 @@ function field_default_insert($entity_type, $entity, $field, $instance, $langcod
// not yet open languages.
if (empty($entity) || (!isset($entity->{$field['field_name']}[$langcode]) && !property_exists($entity, $field['field_name'])) ||
(isset($entity->{$field['field_name']}[$langcode]) && count($entity->{$field['field_name']}[$langcode]) == 0)) {
$items = field_get_default_value($entity_type, $entity, $field, $instance, $langcode);
$items = field_get_default_value($entity, $field, $instance, $langcode);
}
}
/**
* Copies source field values into the entity to be prepared.
*
* @param $entity_type
* The type of $entity; e.g. 'node' or 'user'.
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be prepared for translation.
* @param $field
* The field structure for the operation.
......@@ -101,12 +97,12 @@ function field_default_insert($entity_type, $entity, $field, $instance, $langcod
* The language the entity has to be translated to.
* @param $items
* $entity->{$field['field_name']}[$langcode], or an empty array if unset.
* @param $source_entity
* @param \Drupal\Core\Entity\EntityInterface $source_entity
* The source entity holding the field values to be translated.
* @param $source_langcode
* The source language from which to translate.
*/
function field_default_prepare_translation($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode) {
function field_default_prepare_translation(EntityInterface $entity, $field, $instance, $langcode, &$items, EntityInterface $source_entity, $source_langcode) {
$field_name = $field['field_name'];
// If the field is untranslatable keep using LANGUAGE_NOT_SPECIFIED.
if ($langcode == LANGUAGE_NOT_SPECIFIED) {
......
......@@ -4,8 +4,8 @@
* Attach custom data fields to Drupal entities.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Entity\Query\QueryFactory;
/*
* Load all public Field API functions. Drupal currently has no
......@@ -436,12 +436,12 @@ function field_entity_field_info($entity_type) {
*
* @param $field_langcodes
* A reference to an array of language codes keyed by field name.
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be displayed.
* @param $langcode
* The language code $entity has to be displayed in.
*/
function field_language_fallback(&$field_langcodes, $entity, $langcode) {
function field_language_fallback(&$field_langcodes, EntityInterface $entity, $langcode) {
// Lazily init fallback candidates to avoid unnecessary calls.
$fallback_candidates = NULL;
......@@ -546,9 +546,7 @@ function field_associate_fields($module) {
/**
* Helper function to get the default value for a field on an entity.
*
* @param $entity_type
* The type of $entity; e.g., 'node' or 'user'.
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity for the operation.
* @param $field
* The field structure.
......@@ -557,11 +555,11 @@ function field_associate_fields($module) {
* @param $langcode
* The field language to fill-in with the default value.
*/
function field_get_default_value($entity_type, $entity, $field, $instance, $langcode = NULL) {
function field_get_default_value(EntityInterface $entity, $field, $instance, $langcode = NULL) {
$items = array();
if (!empty($instance['default_value_function'])) {
$function = $instance['default_value_function'];
$items = $function($entity_type, $entity, $field, $instance, $langcode);
$items = $function($entity, $field, $instance, $langcode);
}
elseif (!empty($instance['default_value'])) {
$items = $instance['default_value'];
......@@ -729,7 +727,7 @@ function field_view_mode_settings($entity_type, $bundle) {
* @todo Remove when all steps in the view callstack receive the
* entity_display.
*
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity.
* @param $view_mode
* The view mode.
......@@ -738,7 +736,7 @@ function field_view_mode_settings($entity_type, $bundle) {
* The display options to be used when viewing the entity's pseudo-fields in
* the view mode.
*/
function field_extra_fields_get_display($entity, $view_mode) {
function field_extra_fields_get_display(EntityInterface $entity, $view_mode) {
$entity_display = entity_get_render_display($entity, $view_mode);
$extra_fields = field_info_extra_fields($entity->entityType(), $entity->bundle(), 'display');
......@@ -812,9 +810,7 @@ function _field_filter_xss_display_allowed_tags() {
/**
* Returns a renderable array for a single field value.
*
* @param $entity_type
* The type of $entity; e.g., 'node' or 'user'.
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity containing the field to display. Must at least contain the ID
* key and the field data to display.
* @param $field_name
......@@ -832,18 +828,18 @@ function _field_filter_xss_display_allowed_tags() {
* @return
* A renderable array for the field value.
*/
function field_view_value($entity_type, $entity, $field_name, $item, $display = array(), $langcode = NULL) {
function field_view_value(EntityInterface $entity, $field_name, $item, $display = array(), $langcode = NULL) {
$output = array();
if ($field = field_info_field($field_name)) {
// Determine the langcode that will be used by language fallback.
$langcode = field_language($entity_type, $entity, $field_name, $langcode);
$langcode = field_language($entity, $field_name, $langcode);
// Push the item as the single value for the field, and defer to
// field_view_field() to build the render array for the whole field.
$clone = clone $entity;
$clone->{$field_name}[$langcode] = array($item);
$elements = field_view_field($entity_type, $clone, $field_name, $display, $langcode);
$elements = field_view_field($clone, $field_name, $display, $langcode);
// Extract the part of the render array we need.
$output = isset($elements[0]) ? $elements[0] : array();
......@@ -872,11 +868,8 @@ function field_view_value($entity_type, $entity, $field_name, $item, $display =
* The function takes care of invoking the prepare_view steps. It also respects
* field access permissions.
*
* @param $entity_type
* The type of $entity; e.g., 'node' or 'user'.
* @param $entity
* The entity containing the field to display. Must at least contain the ID
* key and the field data to display.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity containing the field to display.
* @param $field_name
* The name of the field to display.
* @param $display_options
......@@ -909,12 +902,12 @@ function field_view_value($entity_type, $entity, $field_name, $item, $display =
*
* @see field_view_value()
*/
function field_view_field($entity_type, $entity, $field_name, $display_options = array(), $langcode = NULL) {
function field_view_field(EntityInterface $entity, $field_name, $display_options = array(), $langcode = NULL) {
$output = array();
$bundle = $entity->bundle();
// Return nothing if the field doesn't exist.
$instance = field_info_instance($entity_type, $field_name, $bundle);
$instance = field_info_instance($entity->entityType(), $field_name, $bundle);
if (!$instance) {
return $output;
}
......@@ -940,7 +933,7 @@ function field_view_field($entity_type, $entity, $field_name, $display_options =
}
if ($formatter) {
$display_langcode = field_language($entity_type, $entity, $field_name, $langcode);
$display_langcode = field_language($entity, $field_name, $langcode);
$items = $entity->{$field_name}[$display_langcode];
// Invoke prepare_view steps if needed.
......@@ -950,7 +943,7 @@ function field_view_field($entity_type, $entity, $field_name, $display_options =
// First let the field types do their preparation.
$options = array('field_name' => $field_name, 'langcode' => $display_langcode);
$null = NULL;
_field_invoke_multiple('prepare_view', $entity_type, array($id => $entity), $null, $null, $options);
_field_invoke_multiple('prepare_view', $entity->entityType(), array($id => $entity), $null, $null, $options);
// Then let the formatter do its own specific massaging.
$items_multi = array($id => $entity->{$field_name}[$display_langcode]);
......@@ -964,7 +957,6 @@ function field_view_field($entity_type, $entity, $field_name, $display_options =
// Invoke hook_field_attach_view_alter() to let other modules alter the
// renderable array, as in a full field_attach_view() execution.
$context = array(
'entity_type' => $entity_type,
'entity' => $entity,
'view_mode' => $view_mode,
'display_options' => $display_options,
......@@ -982,9 +974,7 @@ function field_view_field($entity_type, $entity, $field_name, $display_options =
/**
* Returns the field items in the language they currently would be displayed.
*
* @param $entity_type
* The type of $entity; e.g., 'node' or 'user'.
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity containing the data to be displayed.
* @param $field_name
* The field to be displayed.
......@@ -995,8 +985,8 @@ function field_view_field($entity_type, $entity, $field_name, $display_options =
* @return
* An array of field items keyed by delta if available, FALSE otherwise.
*/
function field_get_items($entity_type, $entity, $field_name, $langcode = NULL) {
$langcode = field_language($entity_type, $entity, $field_name, $langcode);
function field_get_items(EntityInterface $entity, $field_name, $langcode = NULL) {
$langcode = field_language($entity, $field_name, $langcode);
return isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : FALSE;
}
......@@ -1048,8 +1038,8 @@ function field_has_data($field) {
* @param array $field
* The full field structure array for the field on which the operation is to
* be performed. See field_info_field().
* @param string $entity_type
* The type of $entity; e.g., 'node' or 'user'.
* @param $entity_type
* The type of $entity; for example, 'node' or 'user'.
* @param $entity
* (optional) The entity for the operation.
* @param $account
......
<?php
use Drupal\Core\Entity\EntityInterface;
/**
* @file
* Functions implementing Field API multilingual support.
......@@ -283,9 +285,7 @@ function field_valid_language($langcode, $default = TRUE) {
* Core language fallback rules are provided by field_language_fallback()
* which is called by field_field_language_alter().
*
* @param $entity_type
* The type of $entity.
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be displayed.
* @param $field_name
* (optional) The name of the field to be displayed. Defaults to NULL. If
......@@ -299,10 +299,11 @@ function field_valid_language($langcode, $default = TRUE) {
* A language code if a field name is specified, an array of language codes
* keyed by field name otherwise.
*/
function field_language($entity_type, $entity, $field_name = NULL, $langcode = NULL) {
function field_language(EntityInterface $entity, $field_name = NULL, $langcode = NULL) {
$display_langcodes = &drupal_static(__FUNCTION__, array());
$id = $entity->id();
$bundle = $entity->bundle();
$entity_type = $entity->entityType();
$langcode = field_valid_language($langcode, FALSE);
if (!isset($display_langcodes[$entity_type][$id][$langcode])) {
$display_langcode = array();
......@@ -330,13 +331,12 @@ function field_language($entity_type, $entity, $field_name = NULL, $langcode = N
if (field_has_translation_handler($entity_type)) {
$context = array(
'entity_type' => $entity_type,
'entity' => $entity,
'langcode' => $langcode,
);
// Do not apply core language fallback rules if they are disabled or if
// the entity does not have a translation handler registered.
if (variable_get('field_language_fallback', FALSE) && field_has_translation_handler($context['entity_type'])) {
if (variable_get('field_language_fallback', FALSE) && field_has_translation_handler($entity_type)) {
field_language_fallback($display_langcode, $context['entity'], $context['langcode']);
}
drupal_alter('field_language', $display_langcode, $context);
......
......@@ -105,7 +105,7 @@ public function view(EntityInterface $entity, $langcode, array $items) {
'#theme' => 'field',
'#weight' => $this->weight,
'#title' => $instance['label'],
'#access' => field_access('view', $field, $entity_type, $entity),
'#access' => field_access('view', $field, $entity->entityType(), $entity),
'#label_display' => $this->label,
'#view_mode' => $this->viewMode,
'#language' => $langcode,
......
......@@ -74,7 +74,6 @@ public function __construct($plugin_id, DiscoveryInterface $discovery, FieldInst
* Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::form().
*/
public function form(EntityInterface $entity, $langcode, array $items, array &$form, array &$form_state, $get_delta = NULL) {
$entity_type = $entity->entityType();
$field = $this->field;
$instance = $this->instance;
$field_name = $field['field_name'];
......@@ -87,7 +86,7 @@ public function form(EntityInterface $entity, $langcode, array $items, array &$f
// Populate widgets with default values when creating a new entity.
if (empty($items) && ($entity->isNew())) {
$items = field_get_default_value($entity_type, $entity, $field, $instance, $langcode);
$items = field_get_default_value($entity, $field, $instance, $langcode);
}
// Store field information in $form_state.
......@@ -165,7 +164,7 @@ public function form(EntityInterface $entity, $langcode, array $items, array &$f
// when $langcode is unknown.
'#language' => $langcode,
$langcode => $elements,
'#access' => field_access('edit', $field, $entity_type, $entity),
'#access' => field_access('edit', $field, $entity->entityType(), $entity),
);
return $addition;
......
......@@ -115,7 +115,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
'label' => $this->label,
);
return $function($entity->entityType(), $entity, $this->field, $this->instance, $langcode, $items, $display);
return $function($entity, $this->field, $this->instance, $langcode, $items, $display);
}
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\field\Plugin\views\field;
use Drupal\Core\Entity\EntityInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
......@@ -661,9 +662,8 @@ function get_items($values) {
'views_row_id' => $this->view->row_index,
);
$entity_type = $entity->entityType();
$langcode = $this->field_langcode($entity_type, $entity);
$render_array = field_view_field($entity_type, $entity, $this->definition['field_name'], $display, $langcode);
$langcode = $this->field_langcode($entity);
$render_array = field_view_field($entity, $this->definition['field_name'], $display, $langcode);
$items = array();
if ($this->options['field_api_classes']) {
......@@ -697,17 +697,15 @@ function get_items($values) {
* Replaces values with aggregated values if aggregation is enabled.
* Takes delta settings into account (@todo remove in #1758616).
*
* @param $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be processed.
*
* @return
* TRUE if the processing completed successfully, otherwise FALSE.
*/
function process_entity($entity) {
function process_entity(EntityInterface $entity) {
$processed_entity = clone $entity;
$entity_type = $entity->entityType();
$langcode = $this->field_langcode($entity_type, $processed_entity);
$langcode = $this->field_langcode($processed_entity);
// If we are grouping, copy our group fields into the cloned entity.
// It's possible this will cause some weirdness, but there's only
// so much we can hope to do.
......@@ -835,8 +833,8 @@ function add_self_tokens(&$tokens, $item) {
* Return the language code of the language the field should be displayed in,
* according to the settings.
*/
function field_langcode($entity_type, $entity) {
if (field_is_translatable($entity_type, $this->field_info)) {
function field_langcode(EntityInterface $entity) {
if (field_is_translatable($entity->entityType(), $this->field_info)) {
$default_langcode = language_default()->langcode;
$langcode = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'),
array(drupal_container()->get(LANGUAGE_TYPE_CONTENT)->langcode, $default_langcode),
......@@ -846,7 +844,7 @@ function field_langcode($entity_type, $entity) {
// (or LANGUAGE_NOT_SPECIFIED), in case the field has no data for the selected language.
// field_view_field() does this as well, but since the returned language code
// is used before calling it, the fallback needs to happen explicitly.
$langcode = field_language($entity_type, $entity, $this->field_info['field_name'], $langcode);
$langcode = field_language($entity, $this->field_info['field_name'], $langcode);
return $langcode;
}
......
......@@ -81,7 +81,8 @@ function checkHooksInvocations($expected_hooks, $actual_hooks) {
foreach ($invocations as $argument) {
$found = FALSE;
foreach ($actual_invocations as $actual_arguments) {
if ($actual_arguments[1] == $argument) {
// $entity is sometimes the first and sometimes the second argument.
if ($actual_arguments[0] == $argument || $actual_arguments[1] == $argument) {
$found = TRUE;
break;
}
......
......@@ -340,7 +340,7 @@ function testDeleteField() {
$values[0]['value'] = mt_rand(1, 127);
$entity->{$field['field_name']}[$langcode] = $values;
$entity_type = 'test_entity';
field_attach_insert('test_entity', $entity);
field_attach_insert($entity);
// Verify the field is present on load
$entity = field_test_create_entity(0, 0, $this->instance_definition['bundle']);
......@@ -406,7 +406,7 @@ function testUpdateField() {
$entity->field_update[LANGUAGE_NOT_SPECIFIED][$i]['value'] = $i;
}
// Save the entity.
field_attach_insert('test_entity', $entity);
field_attach_insert($entity);
// Load back and assert there are $cardinality number of values.
$entity = field_test_create_entity($id, $id, $instance['bundle']);
field_attach_load('test_entity', array($id => $entity));
......
......@@ -83,7 +83,7 @@ function setUp() {
*/
function testFieldViewField() {
// No display settings: check that default display settings are used.
$output = field_view_field('test_entity', $this->entity, $this->field_name);
$output = field_view_field($this->entity, $this->field_name);
$this->drupalSetContent(drupal_render($output));
$settings = field_info_formatter_settings('field_test_default');
$setting = $settings['test_formatter_setting'];
......@@ -101,7 +101,7 @@ function testFieldViewField() {
'a