1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay; |
4
|
|
|
|
5
|
|
|
use Drupal\Core\Form\FormStateInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Entity Embed Display reusing file field formatters. |
9
|
|
|
* |
10
|
|
|
* @see \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayInterface |
11
|
|
|
* |
12
|
|
|
* @EntityEmbedDisplay( |
13
|
|
|
* id = "file", |
14
|
|
|
* label = @Translation("File"), |
15
|
|
|
* entity_types = {"file"}, |
16
|
|
|
* deriver = "Drupal\entity_embed\Plugin\Derivative\FieldFormatterDeriver", |
17
|
|
|
* field_type = "file", |
18
|
|
|
* provider = "file" |
19
|
|
|
* ) |
20
|
|
|
*/ |
21
|
|
|
class FileFieldFormatter extends EntityReferenceFieldFormatter { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function getFieldValue() { |
27
|
|
|
$value = parent::getFieldValue(); |
28
|
|
|
$value += array_intersect_key($this->getConfiguration(), array('description' => '')); |
29
|
|
|
return $value; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function defaultConfiguration() { |
36
|
|
|
$defaults = parent::defaultConfiguration(); |
37
|
|
|
// Add support to store file description. |
38
|
|
|
$defaults['description'] = ''; |
39
|
|
|
return $defaults; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function buildConfigurationForm(array $form, FormStateInterface $form_state) { |
46
|
|
|
$form = parent::buildConfigurationForm($form, $form_state); |
47
|
|
|
|
48
|
|
|
// Description is stored in the configuration since it doesn't map to an |
49
|
|
|
// actual HTML attribute. |
50
|
|
|
$form['description'] = array( |
51
|
|
|
'#type' => 'textfield', |
52
|
|
|
'#title' => $this->t('Description'), |
53
|
|
|
'#default_value' => $this->getConfigurationValue('description'), |
54
|
|
|
'#description' => $this->t('The description may be used as the label of the link to the file.'), |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
return $form; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|