FilterFormat.php 1.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

/**
 * @file
 * Contains \Drupal\filter\Plugin\DataType\FilterFormat.
 */

namespace Drupal\filter\Plugin\DataType;

use Drupal\Core\Session\AccountInterface;
11
use Drupal\Core\TypedData\OptionsProviderInterface;
12
use Drupal\Core\TypedData\Plugin\DataType\StringData;
13 14 15 16 17 18 19 20 21

/**
 * The filter format data type.
 *
 * @DataType(
 *   id = "filter_format",
 *   label = @Translation("Filter format")
 * )
 */
22
class FilterFormat extends StringData implements OptionsProviderInterface {
23 24 25 26 27

  /**
   * {@inheritdoc}
   */
  public function getPossibleValues(AccountInterface $account = NULL) {
28
    return array_keys($this->getPossibleOptions($account));
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  }

  /**
   * {@inheritdoc}
   */
  public function getPossibleOptions(AccountInterface $account = NULL) {
    return array_map(function ($format) { return $format->label(); }, filter_formats());
  }

  /**
   * {@inheritdoc}
   */
  public function getSettableValues(AccountInterface $account = NULL) {
    return array_keys($this->getSettableOptions($account));
  }

  /**
   * {@inheritdoc}
   */
  public function getSettableOptions(AccountInterface $account = NULL) {
    // @todo: Avoid calling functions but move to injected dependencies.
    return array_map(function ($format) { return $format->label(); }, filter_formats($account));
  }
}