Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
034d9569
Commit
034d9569
authored
Sep 16, 2013
by
webchick
Browse files
Issue
#2075095
by yched, amateescu: Widget / Formatter methods signatures needlessly complex.
parent
4b7a30ed
Changes
67
Hide whitespace changes
Inline
Side-by-side
core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php
View file @
034d9569
...
...
@@ -11,7 +11,6 @@
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Datetime\Date
;
use
Drupal\Core\Datetime\DrupalDateTime
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityStorageControllerInterface
;
use
Drupal\Core\Entity\Field\FieldDefinitionInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
...
...
@@ -95,7 +94,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
)
{
public
function
viewElements
(
FieldInterface
$items
)
{
$elements
=
array
();
...
...
core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php
View file @
034d9569
...
...
@@ -10,7 +10,6 @@
use
Drupal\field\Annotation\FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\Core\Datetime\DrupalDateTime
;
...
...
@@ -30,7 +29,7 @@ class DateTimePlainFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
)
{
public
function
viewElements
(
FieldInterface
$items
)
{
$elements
=
array
();
...
...
core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php
View file @
034d9569
...
...
@@ -9,13 +9,9 @@
use
Drupal\field\Annotation\FieldWidget
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Widget\WidgetBase
;
use
Drupal\Component\Plugin\Discovery\DiscoveryInterface
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldDefinitionInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\field\Plugin\PluginSettingsBase
;
use
Drupal\field\FieldInstanceInterface
;
use
Drupal\Core\Datetime\DrupalDateTime
;
use
Drupal\datetime\DateHelper
;
/**
...
...
@@ -62,7 +58,7 @@ public function defaultValueFunction() {
/**
* {@inheritdoc}
*/
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
$langcode
,
array
&
$form
,
array
&
$form_state
)
{
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
array
&
$form
,
array
&
$form_state
)
{
$date_order
=
$this
->
getSetting
(
'date_order'
);
$time_type
=
$this
->
getSetting
(
'time_type'
);
$increment
=
$this
->
getSetting
(
'increment'
);
...
...
core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php
View file @
034d9569
...
...
@@ -9,13 +9,9 @@
use
Drupal\field\Annotation\FieldWidget
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Widget\WidgetBase
;
use
Drupal\Component\Plugin\Discovery\DiscoveryInterface
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldDefinitionInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\field\Plugin\PluginSettingsBase
;
use
Drupal\field\FieldInstanceInterface
;
use
Drupal\Core\Datetime\DrupalDateTime
;
/**
* Plugin implementation of the 'datetime_default' widget.
...
...
@@ -66,7 +62,7 @@ public function defaultValueFunction() {
/**
* {@inheritdoc}
*/
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
$langcode
,
array
&
$form
,
array
&
$form_state
)
{
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
array
&
$form
,
array
&
$form_state
)
{
$format_type
=
datetime_default_format_type
();
// We are nesting some sub-elements inside the parent, so we need a wrapper.
...
...
core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php
View file @
034d9569
...
...
@@ -10,7 +10,6 @@
use
Drupal\field\Annotation\FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
/**
...
...
@@ -29,7 +28,7 @@ class MailToFormatter extends FormatterBase {
/**
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
*/
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
)
{
public
function
viewElements
(
FieldInterface
$items
)
{
$elements
=
array
();
foreach
(
$items
as
$delta
=>
$item
)
{
...
...
core/modules/email/lib/Drupal/email/Plugin/field/widget/EmailDefaultWidget.php
View file @
034d9569
...
...
@@ -61,7 +61,7 @@ public function settingsSummary() {
/**
* Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
*/
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
$langcode
,
array
&
$form
,
array
&
$form_state
)
{
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
array
&
$form
,
array
&
$form_state
)
{
$element
[
'value'
]
=
$element
+
array
(
'#type'
=>
'email'
,
'#default_value'
=>
isset
(
$items
[
$delta
]
->
value
)
?
$items
[
$delta
]
->
value
:
NULL
,
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php
View file @
034d9569
...
...
@@ -9,7 +9,6 @@
use
Drupal\field\Annotation\FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\entity_reference
\
RecursiveRenderingException
;
use
Drupal\entity_reference
\
Plugin\field\formatter\EntityReferenceFormatterBase
;
...
...
@@ -79,7 +78,7 @@ public function settingsSummary() {
/**
* {@inheritdoc}
*/
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
)
{
public
function
viewElements
(
FieldInterface
$items
)
{
$view_mode
=
$this
->
getSetting
(
'view_mode'
);
$links
=
$this
->
getSetting
(
'links'
);
...
...
@@ -96,13 +95,13 @@ public function viewElements(EntityInterface $entity, $langcode, FieldInterface
static
$depth
=
0
;
$depth
++
;
if
(
$depth
>
20
)
{
throw
new
RecursiveRenderingException
(
format_string
(
'Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.'
,
array
(
'@entity_type'
=>
$
entity_type
,
'@entity_id'
=>
$item
->
target_id
)));
throw
new
RecursiveRenderingException
(
format_string
(
'Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.'
,
array
(
'@entity_type'
=>
$
item
->
entity
->
entityType
()
,
'@entity_id'
=>
$item
->
target_id
)));
}
if
(
!
empty
(
$item
->
target_id
))
{
$entity
=
clone
$item
->
entity
;
unset
(
$entity
->
content
);
$elements
[
$delta
]
=
entity_view
(
$entity
,
$view_mode
,
$
l
angcode
);
$elements
[
$delta
]
=
entity_view
(
$entity
,
$view_mode
,
$
item
->
getL
angcode
()
);
if
(
empty
(
$links
)
&&
isset
(
$result
[
$delta
][
$target_type
][
$item
->
target_id
][
'links'
]))
{
// Hide the element links.
...
...
@@ -111,11 +110,12 @@ public function viewElements(EntityInterface $entity, $langcode, FieldInterface
}
else
{
// This is an "auto_create" item.
$elements
[
$delta
]
=
array
(
'#markup'
=>
$entity
->
label
());
$elements
[
$delta
]
=
array
(
'#markup'
=>
$
item
->
entity
->
label
());
}
$depth
=
0
;
}
return
$elements
;
}
}
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php
View file @
034d9569
...
...
@@ -7,10 +7,6 @@
namespace
Drupal\entity_reference\Plugin\field\formatter
;
use
Drupal\field\Annotation\FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
/**
...
...
@@ -25,13 +21,13 @@ abstract class EntityReferenceFormatterBase extends FormatterBase {
* values, as other may want to act on those values, even if they can
* not be accessed.
*/
public
function
prepareView
(
array
$entities
,
$langcode
,
array
$
items
)
{
public
function
prepareView
(
array
$entities
_
items
)
{
$target_ids
=
array
();
$revision_ids
=
array
();
// Collect every possible entity attached to any of the entities.
foreach
(
$entities
as
$id
=>
$entity
)
{
foreach
(
$items
[
$id
]
as
$item
)
{
foreach
(
$entities
_items
as
$items
)
{
foreach
(
$items
as
$item
)
{
if
(
!
empty
(
$item
->
revision_id
))
{
$revision_ids
[]
=
$item
->
revision_id
;
}
...
...
@@ -52,31 +48,30 @@ public function prepareView(array $entities, $langcode, array $items) {
if
(
$revision_ids
)
{
// We need to load the revisions one by-one.
foreach
(
$revision_ids
as
$revision_id
)
{
$entity
=
entity_revision_load
(
$target_type
,
$revision_id
);
$
target_
entity
=
entity_revision_load
(
$target_type
,
$revision_id
);
// Use the revision ID in the key.
$identifier
=
$entity
->
id
()
.
':'
.
$revision_id
;
$target_entities
[
$identifier
]
=
$entity
;
$identifier
=
$
target_
entity
->
id
()
.
':'
.
$revision_id
;
$target_entities
[
$identifier
]
=
$
target_
entity
;
}
}
// Iterate through the fieldable entities again to attach the loaded data.
foreach
(
$entities
as
$id
=>
$entity
)
{
foreach
(
$entities
_items
as
$items
)
{
$rekey
=
FALSE
;
foreach
(
$items
[
$id
]
as
$delta
=>
$item
)
{
foreach
(
$items
as
$item
)
{
// If we have a revision ID, the key uses it as well.
$identifier
=
!
empty
(
$item
->
revision_id
)
?
$item
->
target_id
.
':'
.
$item
->
revision_id
:
$item
->
target_id
;
if
(
$item
->
target_id
!==
0
)
{
if
(
!
isset
(
$target_entities
[
$identifier
]))
{
// The entity no longer exists, so remove the key.
// The entity no longer exists, so empty the item.
$item
->
setValue
(
NULL
);
$rekey
=
TRUE
;
unset
(
$items
[
$id
][
$delta
]);
continue
;
}
$entity
=
$target_entities
[
$identifier
];
$item
->
entity
=
$entity
;
$item
->
entity
=
$target_entities
[
$identifier
];
if
(
!
$entity
->
access
(
'view'
))
{
if
(
!
$
item
->
entity
->
access
(
'view'
))
{
continue
;
}
}
...
...
@@ -88,10 +83,11 @@ public function prepareView(array $entities, $langcode, array $items) {
$item
->
access
=
TRUE
;
}
// Rekey the items array if needed.
if
(
$rekey
)
{
// Rekey the items array.
$items
[
$id
]
=
array_values
(
$items
[
$id
]);
$items
->
filterEmptyValues
();
}
}
}
}
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceIdFormatter.php
View file @
034d9569
...
...
@@ -9,7 +9,6 @@
use
Drupal\field\Annotation\FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\entity_reference
\
Plugin\field\formatter\EntityReferenceFormatterBase
;
...
...
@@ -30,7 +29,7 @@ class EntityReferenceIdFormatter extends EntityReferenceFormatterBase {
/**
* Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements().
*/
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
)
{
public
function
viewElements
(
FieldInterface
$items
)
{
$elements
=
array
();
foreach
(
$items
as
$delta
=>
$item
)
{
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php
View file @
034d9569
...
...
@@ -9,7 +9,6 @@
use
Drupal\field\Annotation\FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\entity_reference
\
Plugin\field\formatter\EntityReferenceFormatterBase
;
...
...
@@ -55,7 +54,7 @@ public function settingsSummary() {
/**
* {@inheritdoc}
*/
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
)
{
public
function
viewElements
(
FieldInterface
$items
)
{
$elements
=
array
();
foreach
(
$items
as
$delta
=>
$item
)
{
...
...
@@ -83,4 +82,5 @@ public function viewElements(EntityInterface $entity, $langcode, FieldInterface
return
$elements
;
}
}
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php
View file @
034d9569
...
...
@@ -40,7 +40,7 @@ class AutocompleteWidget extends AutocompleteWidgetBase {
/**
* {@inheritdoc}
*/
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
$langcode
,
array
&
$form
,
array
&
$form_state
)
{
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
array
&
$form
,
array
&
$form_state
)
{
// We let the Field API handles multiple values for us, only take care of
// the one matching our delta.
if
(
isset
(
$items
[
$delta
]))
{
...
...
@@ -50,7 +50,7 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang
$items
->
setValue
(
array
());
}
return
parent
::
formElement
(
$items
,
$delta
,
$element
,
$langcode
,
$form
,
$form_state
);
return
parent
::
formElement
(
$items
,
$delta
,
$element
,
$form
,
$form_state
);
}
/**
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php
View file @
034d9569
...
...
@@ -70,9 +70,10 @@ public function settingsSummary() {
/**
* {@inheritdoc}
*/
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
$langcode
,
array
&
$form
,
array
&
$form_state
)
{
public
function
formElement
(
FieldInterface
$items
,
$delta
,
array
$element
,
array
&
$form
,
array
&
$form_state
)
{
global
$user
;
$entity
=
$element
[
'#entity'
];
$entity
=
$items
->
getEntity
();
// Prepare the autocomplete path.
$autocomplete_path
=
$this
->
getSetting
(
'autocomplete_path'
);
...
...
core/modules/field/field.api.php
View file @
034d9569
...
...
@@ -198,10 +198,8 @@ function hook_field_widget_info_alter(array &$info) {
* - form: The form structure to which widgets are being attached. This may be
* a full form structure, or a sub-element of a larger form.
* - widget: The widget plugin instance.
* - field_definition: The field definition.
* - entity: The entity.
* - langcode: The language associated with $items.
* - items: Array of default values for this field.
* - items: The field values, as a \Drupal\Core\Entity\Field\FieldInterface
* object.
* - delta: The order of this item in the array of subelements (0, 1, 2, etc).
* - default: A boolean indicating whether the form is being shown as a dummy
* form to set default values.
...
...
@@ -211,7 +209,8 @@ function hook_field_widget_info_alter(array &$info) {
*/
function
hook_field_widget_form_alter
(
&
$element
,
&
$form_state
,
$context
)
{
// Add a css class to widget form elements for all fields of type mytype.
if
(
$context
[
'field'
][
'type'
]
==
'mytype'
)
{
$field_definition
=
$context
[
'items'
]
->
getFieldDefinition
();
if
(
$field_definition
->
getFieldType
()
==
'mytype'
)
{
// Be sure not to overwrite existing attributes.
$element
[
'#attributes'
][
'class'
][]
=
'myclass'
;
}
...
...
core/modules/field/field.attach.inc
View file @
034d9569
...
...
@@ -123,7 +123,7 @@ function field_invoke_method($method, $target_function, EntityInterface $entity,
$items
=
$entity
->
getTranslation
(
$langcode
)
->
get
(
$field_name
);
$items
->
filterEmptyValues
();
$result
=
$target
->
$method
(
$entity
,
$langcode
,
$items
,
$a
,
$b
);
$result
=
$target
->
$method
(
$items
,
$a
,
$b
);
if
(
isset
(
$result
))
{
// For methods with array results, we merge results together.
...
...
@@ -187,7 +187,6 @@ function field_invoke_method_multiple($method, $target_function, array $entities
$options
+=
$default_options
;
$instances
=
array
();
$grouped_entities
=
array
();
$grouped_items
=
array
();
$grouped_targets
=
array
();
$return
=
array
();
...
...
@@ -224,8 +223,7 @@ function field_invoke_method_multiple($method, $target_function, array $entities
$langcode
=
!
empty
(
$options
[
'langcode'
][
$id
])
?
$options
[
'langcode'
][
$id
]
:
$options
[
'langcode'
];
$langcodes
=
_field_language_suggestion
(
$available_langcodes
,
$langcode
,
$field_name
);
foreach
(
$langcodes
as
$langcode
)
{
// Group the entities and items corresponding to the current field.
$grouped_entities
[
$instance_id
][
$langcode
][
$id
]
=
$entities
[
$id
];
// Group the items corresponding to the current field.
$items
=
$entity
->
getTranslation
(
$langcode
)
->
get
(
$field_name
);
$items
->
filterEmptyValues
();
$grouped_items
[
$instance_id
][
$langcode
][
$id
]
=
$items
;
...
...
@@ -238,12 +236,9 @@ function field_invoke_method_multiple($method, $target_function, array $entities
// For each instance, invoke the method and collect results.
foreach
(
$instances
as
$instance_id
=>
$instance
)
{
$field_name
=
$instance
[
'field_name'
];
// Iterate over all the field translations.
foreach
(
$grouped_items
[
$instance_id
]
as
$langcode
=>
$items
)
{
$entities
=
$grouped_entities
[
$instance_id
][
$langcode
];
$results
=
$grouped_targets
[
$instance_id
]
->
$method
(
$entities
,
$langcode
,
$items
,
$a
,
$b
);
$results
=
$grouped_targets
[
$instance_id
]
->
$method
(
$items
,
$a
,
$b
);
if
(
isset
(
$results
))
{
// Collect results by entity.
...
...
core/modules/field/field.module
View file @
034d9569
...
...
@@ -697,9 +697,8 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options
// Invoke the formatter's prepareView() and view() methods.
$items
=
$entity
->
getTranslation
(
$display_langcode
)
->
get
(
$field_name
);
$id
=
$entity
->
id
();
$formatter
->
prepareView
(
array
(
$id
=>
$entity
),
$display_langcode
,
array
(
$id
=>
$items
));
$result
=
$formatter
->
view
(
$entity
,
$display_langcode
,
$items
);
$formatter
->
prepareView
(
array
(
$entity
->
id
()
=>
$items
));
$result
=
$formatter
->
view
(
$items
);
// Invoke hook_field_attach_view_alter() to let other modules alter the
// renderable array, as in a full field_attach_view() execution.
...
...
core/modules/field/field.multilingual.inc
View file @
034d9569
...
...
@@ -34,7 +34,7 @@
* is attached to supports translation.
*
* By default, field_invoke_method() processes a field in all available
* languages, unless
they are
given a language code suggestion. Based on that
* languages, unless
it is
given a language code suggestion. Based on that
* suggestion, _field_language_suggestion() determines the languages to act on.
*
* Most field_attach_*() functions act on all available language codes, except
...
...
core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php
View file @
034d9569
...
...
@@ -78,11 +78,10 @@ protected function getDefaultValue() {
*/
public
function
defaultValuesForm
(
array
&
$form
,
array
&
$form_state
)
{
if
(
empty
(
$this
->
getFieldDefinition
()
->
default_value_function
))
{
$widget
=
$this
->
defaultValueWidget
(
$form_state
);
// Place the input in a separate place in the submitted values tree.
$widget
=
$this
->
defaultValueWidget
(
$form_state
);
$element
=
array
(
'#parents'
=>
array
(
'default_value_input'
));
$element
+=
$widget
->
form
(
$this
->
getEntity
(),
$this
->
getLangcode
(),
$this
,
$element
,
$form_state
);
$element
+=
$widget
->
form
(
$this
,
$element
,
$form_state
);
return
$element
;
}
...
...
@@ -92,12 +91,9 @@ public function defaultValuesForm(array &$form, array &$form_state) {
* {@inheritdoc}
*/
public
function
defaultValuesFormValidate
(
array
$element
,
array
&
$form
,
array
&
$form_state
)
{
$entity
=
$this
->
getEntity
();
$langcode
=
$this
->
getLangcode
();
// Extract the submitted value, and validate it.
$widget
=
$this
->
defaultValueWidget
(
$form_state
);
$widget
->
extractFormValues
(
$entity
,
$langcode
,
$this
,
$element
,
$form_state
);
$widget
->
extractFormValues
(
$this
,
$element
,
$form_state
);
$violations
=
$this
->
validate
();
if
(
count
(
$violations
))
{
...
...
@@ -108,7 +104,7 @@ public function defaultValuesFormValidate(array $element, array &$form, array &$
field_form_set_state
(
$element
[
'#parents'
],
$field_name
,
$form_state
,
$field_state
);
// Assign reported errors to the correct form element.
$widget
->
flagErrors
(
$entity
,
$langcode
,
$this
,
$element
,
$form_state
);
$widget
->
flagErrors
(
$this
,
$element
,
$form_state
);
}
}
...
...
@@ -118,7 +114,7 @@ public function defaultValuesFormValidate(array $element, array &$form, array &$
public
function
defaultValuesFormSubmit
(
array
$element
,
array
&
$form
,
array
&
$form_state
)
{
// Extract the submitted value, and return it as an array.
$widget
=
$this
->
defaultValueWidget
(
$form_state
);
$widget
->
extractFormValues
(
$this
->
getEntity
(),
$this
->
getLangcode
(),
$this
,
$element
,
$form_state
);
$widget
->
extractFormValues
(
$this
,
$element
,
$form_state
);
return
$this
->
getValue
();
}
...
...
core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php
View file @
034d9569
...
...
@@ -7,7 +7,6 @@
namespace
Drupal\field\Plugin\Type\Formatter
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldDefinitionInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\field\FieldInstanceInterface
;
...
...
@@ -74,11 +73,12 @@ public function __construct($plugin_id, array $plugin_definition, FieldDefinitio
/**
* {@inheritdoc}
*/
public
function
view
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
)
{
public
function
view
(
FieldInterface
$items
)
{
$addition
=
array
();
$elements
=
$this
->
viewElements
(
$entity
,
$langcode
,
$items
);
$elements
=
$this
->
viewElements
(
$items
);
if
(
$elements
)
{
$entity
=
$items
->
getEntity
();
$entity_type
=
$entity
->
entityType
();
$field_name
=
$this
->
fieldDefinition
->
getFieldName
();
$info
=
array
(
...
...
@@ -87,7 +87,7 @@ public function view(EntityInterface $entity, $langcode, FieldInterface $items)
'#access'
=>
$this
->
checkFieldAccess
(
'view'
,
$entity
),
'#label_display'
=>
$this
->
label
,
'#view_mode'
=>
$this
->
viewMode
,
'#language'
=>
$
l
angcode
,
'#language'
=>
$
items
->
getL
angcode
()
,
'#field_name'
=>
$field_name
,
'#field_type'
=>
$this
->
fieldDefinition
->
getFieldType
(),
'#field_translatable'
=>
$this
->
fieldDefinition
->
isFieldTranslatable
(),
...
...
@@ -121,7 +121,7 @@ public function settingsSummary() {
/**
* {@inheritdoc}
*/
public
function
prepareView
(
array
$entities
,
$langcode
,
array
$
items
)
{
}
public
function
prepareView
(
array
$entities
_
items
)
{
}
/**
* Returns whether the currently logged in user has access to the field.
...
...
core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterInterface.php
View file @
034d9569
...
...
@@ -7,7 +7,6 @@
namespace
Drupal\field\Plugin\Type\Formatter
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\field\Plugin\PluginSettingsInterface
;
...
...
@@ -61,45 +60,33 @@ public function settingsSummary();
* Changes or additions to field values are done by alterings the $items
* parameter by reference.
*
* @param array $entities
* Array of entities being displayed, keyed by entity ID.
* @param string $langcode
* The language the field values are to be shown in. If no language is
* provided the current language is used.
* @param array $items
* Array of field values for the entities, keyed by entity ID.
* @param array $entities_items
* Array of field values (Drupal\Core\Entity\Field\FieldInterface), keyed by
* entity ID.
*/
public
function
prepareView
(
array
$entities
,
$langcode
,
array
$
items
);
public
function
prepareView
(
array
$entities
_
items
);
/**
* Builds a renderable array for one field on one entity instance.
*
* @param Drupal\Core\Entity\EntityInterface $entity
* The entity being displayed.
* @param string $langcode
* The language associated with $items.
* @param Drupal\Core\Entity\Field\FieldInterface $items
* The field value
for the entity for the language
.
* The field value
s to be rendered
.
*
* @return array
* A renderable array for a themed field with its label and all its values.
*/
public
function
view
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
);
public
function
view
(
FieldInterface
$items
);
/**
* Builds a renderable array for a field value.
*
* @param Drupal\Core\Entity\EntityInterface $entity
* The entity being displayed.
* @param string $langcode
* The language associated with $items.
* @param array $items
* Array of values for this field.
* @param Drupal\Core\Entity\Field\FieldInterface $items
* The field values to be rendered.
*
* @return array
* A renderable array for $items, as an array of child elements keyed by
* numeric indexes starting from 0.
*/
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
);
public
function
viewElements
(
FieldInterface
$items
);
}
core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php
View file @
034d9569
...
...
@@ -8,7 +8,6 @@
namespace
Drupal\field\Plugin\Type\Widget
;
use
Drupal\Component\Utility\NestedArray
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\Field\FieldDefinitionInterface
;
use
Drupal\Core\Entity\Field\FieldInterface
;
use
Drupal\field\FieldInstanceInterface
;
...
...
@@ -56,7 +55,7 @@ public function __construct($plugin_id, array $plugin_definition, FieldDefinitio
/**
* {@inheritdoc}
*/
public
function
form
(
EntityInterface
$entity
,
$langcode
,
FieldInterface
$items
,
array
&
$form
,
array
&
$form_state
,
$get_delta
=
NULL
)
{
public
function
form
(
FieldInterface
$items
,
array
&
$form
,
array
&
$form_state
,
$get_delta
=
NULL
)
{
$field_name
=
$this
->
fieldDefinition
->
getFieldName
();
$parents
=
$form
[
'#parents'
];
...
...
@@ -83,7 +82,7 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items,
'#title'
=>
check_plain
(
$this
->
fieldDefinition
->
getFieldLabel
()),
'#description'
=>
field_filter_xss
(
\
Drupal
::
token
()
->
replace
(
$this
->
fieldDefinition
->
getFieldDescription
())),
);
$element
=
$this
->
formSingleElement
(
$entity
,
$items
,
$delta
,
$langcode
,
$element
,
$form
,
$form_state
);
$element
=
$this
->
formSingleElement
(
$items
,
$delta
,
$element
,
$form
,
$form_state
);
if
(
$element
)
{
if
(
isset
(
$get_delta
))
{
...
...
@@ -102,7 +101,7 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items,