Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
984940b8
Commit
984940b8
authored
Jun 14, 2013
by
Alex Pott
Browse files
Issue
#1985344
by tim.plunkett, swentel: Add a dedicated @FieldFormatter annotation.
parent
95368fca
Changes
40
Hide whitespace changes
Inline
Side-by-side
core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\datetime\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -17,7 +17,7 @@
/**
* Plugin implementation of the 'datetime_default' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "datetime_default",
* module = "datetime",
* label = @Translation("Default"),
...
...
core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\datetime\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -16,7 +16,7 @@
/**
* Plugin implementation of the 'datetime_plain' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "datetime_plain",
* module = "datetime",
* label = @Translation("Plain"),
...
...
core/modules/edit/edit.module
View file @
984940b8
...
...
@@ -133,6 +133,23 @@ function edit_library_info() {
return
$libraries
;
}
/**
* Implements hook_field_formatter_info_alter().
*
* Edit extends the @FieldFormatter annotation with the following keys:
* - edit: currently only contains one subkey 'editor' which indicates which
* in-place editor should be used. Possible values are 'form', 'direct' or
* 'disabled'.
*/
function
edit_field_formatter_info_alter
(
&
$info
)
{
foreach
(
$info
as
$key
=>
$settings
)
{
// Set in-place editor to form if none is supplied.
if
(
empty
(
$settings
[
'edit'
]))
{
$info
[
$key
][
'edit'
]
=
array
(
'editor'
=>
'form'
);
}
}
}
/**
* Implements hook_preprocess_HOOK() for field.tpl.php.
*/
...
...
core/modules/edit/lib/Drupal/edit/EditorSelector.php
View file @
984940b8
...
...
@@ -63,7 +63,7 @@ public function getEditor($formatter_type, FieldInstance $instance, array $items
// 'form' editor, since that can work for any field. Formatter definitions
// can use 'disabled' to explicitly opt out of in-place editing.
$formatter_info
=
field_info_formatter_types
(
$formatter_type
);
$editor_id
=
isset
(
$formatter_info
[
'edit'
][
'editor'
]
)
?
$formatter_info
[
'edit'
][
'editor'
]
:
'form'
;
$editor_id
=
$formatter_info
[
'edit'
][
'editor'
];
if
(
$editor_id
===
'disabled'
)
{
return
;
}
...
...
core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\email\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'email_mailto' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "email_mailto",
* module = "email",
* label = @Translation("Email"),
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\entity_reference\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\entity_reference
\
RecursiveRenderingException
;
...
...
@@ -16,7 +16,7 @@
/**
* Plugin implementation of the 'entity reference rendered entity' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "entity_reference_entity_view",
* module = "entity_reference",
* label = @Translation("Rendered entity"),
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\entity_reference\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceIdFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\entity_reference\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\entity_reference
\
Plugin\field\formatter\EntityReferenceFormatterBase
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'entity reference ID' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "entity_reference_entity_id",
* module = "entity_reference",
* label = @Translation("Entity ID"),
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\entity_reference\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\entity_reference
\
Plugin\field\formatter\EntityReferenceFormatterBase
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'entity reference label' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "entity_reference_label",
* module = "entity_reference",
* label = @Translation("Label"),
...
...
core/modules/field/lib/Drupal/field/Annotation/FieldFormatter.php
0 → 100644
View file @
984940b8
<?php
/**
* @file
* Contains \Drupal\field\Annotation\FieldFormatter.
*/
namespace
Drupal\field\Annotation
;
use
Drupal\Component\Annotation\Plugin
;
/**
* Defines a FieldFormatter annotation object.
*
* Formatters handle the display of field values. Formatter hooks are typically
* called by the Field Attach API field_attach_prepare_view() and
* field_attach_view() functions.
*
* Additional annotation keys for formatters can be defined in
* hook_field_formatter_info_alter().
*
* @Annotation
*
* @see \Drupal\field\Plugin\Type\Formatter\FormatterPluginManager
* @see \Drupal\field\Plugin\Type\Formatter\FormatterInterface
*/
class
FieldFormatter
extends
Plugin
{
/**
* The plugin ID.
*
* @var string
*/
public
$id
;
/**
* The human-readable name of the formatter type.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public
$label
;
/**
* A short description of the formatter type.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public
$description
;
/**
* The name of the module providing the formatter.
*
* @var string
*/
public
$module
;
/**
* The name of the field formatter class.
*
* This is not provided manually, it will be added by the discovery mechanism.
*
* @var string
*/
public
$class
;
/**
* An array of field types the formatter supports.
*
* @var array
*/
public
$field_types
=
array
();
/**
* An array whose keys are the names of the settings available to the
* formatter type, and whose values are the default values for those settings.
*
* @var array
*/
public
$settings
=
array
();
}
core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterFactory.php
deleted
100644 → 0
View file @
95368fca
<?php
/**
* @file
* Definition of Drupal\field\Plugin\Type\Formatter\FormatterFactory.
*/
namespace
Drupal\field\Plugin\Type\Formatter
;
use
Drupal\Component\Plugin\Factory\DefaultFactory
;
/**
* Factory class for the Formatter plugin type.
*/
class
FormatterFactory
extends
DefaultFactory
{
/**
* Overrides Drupal\Component\Plugin\Factory\DefaultFactory::createInstance().
*/
public
function
createInstance
(
$plugin_id
,
array
$configuration
)
{
$plugin_definition
=
$this
->
discovery
->
getDefinition
(
$plugin_id
);
$plugin_class
=
static
::
getPluginClass
(
$plugin_id
,
$plugin_definition
);
return
new
$plugin_class
(
$plugin_id
,
$plugin_definition
,
$configuration
[
'instance'
],
$configuration
[
'settings'
],
$configuration
[
'label'
],
$configuration
[
'view_mode'
]);
}
}
core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php
View file @
984940b8
...
...
@@ -8,7 +8,7 @@
namespace
Drupal\field\Plugin\Type\Formatter
;
use
Drupal\Component\Plugin\PluginManagerBase
;
use
Drupal\Component\Plugin\
Discovery\ProcessDecora
tor
;
use
Drupal\Component\Plugin\
Factory\DefaultFac
tor
y
;
use
Drupal\Core\Plugin\Discovery\CacheDecorator
;
use
Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery
;
use
Drupal\Core\Plugin\Discovery\AlterDecorator
;
...
...
@@ -26,14 +26,6 @@ class FormatterPluginManager extends PluginManagerBase {
*/
protected
$formatterOptions
;
/**
* Overrides Drupal\Component\Plugin\PluginManagerBase:$defaults.
*/
protected
$defaults
=
array
(
'field_types'
=>
array
(),
'settings'
=>
array
(),
);
/**
* Constructs a FormatterPluginManager object.
*
...
...
@@ -42,12 +34,19 @@ class FormatterPluginManager extends PluginManagerBase {
* keyed by the corresponding namespace to look for plugin implementations,
*/
public
function
__construct
(
\
Traversable
$namespaces
)
{
$
this
->
discovery
=
new
AnnotatedClassDiscovery
(
'field/formatter'
,
$namespaces
);
$this
->
discovery
=
new
ProcessDecorator
(
$this
->
discov
er
y
,
array
(
$this
,
'processDefinition'
)
);
$
annotation_namespaces
=
array
(
'Drupal\field\Annotation'
=>
$namespaces
[
'Drupal\field'
]
);
$this
->
discovery
=
new
AnnotatedClassDiscovery
(
'field/formatt
er
'
,
$namespaces
,
$annotation_namespaces
,
'Drupal\field\Annotation\FieldFormatter'
);
$this
->
discovery
=
new
AlterDecorator
(
$this
->
discovery
,
'field_formatter_info'
);
$this
->
discovery
=
new
CacheDecorator
(
$this
->
discovery
,
'field_formatter_types'
,
'field'
);
}
$this
->
factory
=
new
FormatterFactory
(
$this
->
discovery
);
/**
* {@inheritdoc}
*/
public
function
createInstance
(
$plugin_id
,
array
$configuration
)
{
$plugin_definition
=
$this
->
discovery
->
getDefinition
(
$plugin_id
);
$plugin_class
=
DefaultFactory
::
getPluginClass
(
$plugin_id
,
$plugin_definition
);
return
new
$plugin_class
(
$plugin_id
,
$plugin_definition
,
$configuration
[
'instance'
],
$configuration
[
'settings'
],
$configuration
[
'label'
],
$configuration
[
'view_mode'
]);
}
/**
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldDefaultFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\field_test\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'field_test_default' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "field_test_default",
* module = "field_test",
* label = @Translation("Default"),
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldEmptyFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
*/
namespace
Drupal\field_test\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'field_empty_test' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "field_empty_test",
* module = "field_test",
* label = @Translation("Field empty test"),
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldMultipleFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\field_test\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'field_test_multiple' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "field_test_multiple",
* module = "field_test",
* label = @Translation("Multiple"),
...
...
core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldPrepareViewFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\field_test\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'field_test_with_prepare_view' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "field_test_with_prepare_view",
* module = "field_test",
* label = @Translation("With prepare step"),
...
...
core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\file\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'file_default' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "file_default",
* module = "file",
* label = @Translation("Generic file"),
...
...
core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\file\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'file_rss_enclosure' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "file_rss_enclosure",
* module = "file",
* label = @Translation("RSS enclosure"),
...
...
core/modules/file/lib/Drupal/file/Plugin/field/formatter/TableFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\file\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'file_table' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "file_table",
* module = "file",
* label = @Translation("Table of files"),
...
...
core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php
View file @
984940b8
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\file\Plugin\field\formatter
;
use
Drupal\
Component
\Annotation\
Plugin
;
use
Drupal\
field
\Annotation\
FieldFormatter
;
use
Drupal\Core\Annotation\Translation
;
use
Drupal\field\Plugin\Type\Formatter\FormatterBase
;
use
Drupal\Core\Entity\EntityInterface
;
...
...
@@ -15,7 +15,7 @@
/**
* Plugin implementation of the 'file_url_plain' formatter.
*
* @
Plugin
(
* @
FieldFormatter
(
* id = "file_url_plain",
* module = "file",
* label = @Translation("URL to file"),
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment