FilterFormat.php

Same filename in this branch
  1. 8.9.x core/modules/filter/src/Entity/FilterFormat.php
  2. 8.9.x core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php
  3. 8.9.x core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php
Same filename and directory in other branches
  1. 9 core/modules/filter/src/Entity/FilterFormat.php
  2. 9 core/modules/filter/src/Plugin/DataType/FilterFormat.php
  3. 9 core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php
  4. 9 core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php
  5. 10 core/modules/filter/src/Entity/FilterFormat.php
  6. 10 core/modules/filter/src/Plugin/DataType/FilterFormat.php
  7. 10 core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php
  8. 10 core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php
  9. 11.x core/modules/filter/src/Entity/FilterFormat.php
  10. 11.x core/modules/filter/src/Plugin/DataType/FilterFormat.php
  11. 11.x core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php
  12. 11.x core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php

Namespace

Drupal\filter\Plugin\DataType

File

core/modules/filter/src/Plugin/DataType/FilterFormat.php

View source
<?php

namespace Drupal\filter\Plugin\DataType;

use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TypedData\OptionsProviderInterface;
use Drupal\Core\TypedData\Plugin\DataType\StringData;

/**
 * The filter format data type.
 *
 * @DataType(
 *   id = "filter_format",
 *   label = @Translation("Filter format")
 * )
 */
class FilterFormat extends StringData implements OptionsProviderInterface {
    
    /**
     * {@inheritdoc}
     */
    public function getPossibleValues(AccountInterface $account = NULL) {
        return array_keys($this->getPossibleOptions($account));
    }
    
    /**
     * {@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));
    }

}

Classes

Title Deprecated Summary
FilterFormat The filter format data type.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.