Version 1
[yaffs-website] / web / core / modules / filter / src / Plugin / DataType / FilterFormat.php
1 <?php
2
3 namespace Drupal\filter\Plugin\DataType;
4
5 use Drupal\Core\Session\AccountInterface;
6 use Drupal\Core\TypedData\OptionsProviderInterface;
7 use Drupal\Core\TypedData\Plugin\DataType\StringData;
8
9 /**
10  * The filter format data type.
11  *
12  * @DataType(
13  *   id = "filter_format",
14  *   label = @Translation("Filter format")
15  * )
16  */
17 class FilterFormat extends StringData implements OptionsProviderInterface {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function getPossibleValues(AccountInterface $account = NULL) {
23     return array_keys($this->getPossibleOptions($account));
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   public function getPossibleOptions(AccountInterface $account = NULL) {
30     return array_map(function ($format) { return $format->label(); }, filter_formats());
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function getSettableValues(AccountInterface $account = NULL) {
37     return array_keys($this->getSettableOptions($account));
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function getSettableOptions(AccountInterface $account = NULL) {
44     // @todo: Avoid calling functions but move to injected dependencies.
45     return array_map(function ($format) { return $format->label(); }, filter_formats($account));
46   }
47
48 }