FilterFormat.php

Same filename in this branch
  1. 11.x core/modules/filter/src/Entity/FilterFormat.php
  2. 11.x core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php
  3. 11.x core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php
Same filename and directory in other branches
  1. 10 core/modules/filter/src/Entity/FilterFormat.php
  2. 10 core/modules/filter/src/Plugin/DataType/FilterFormat.php
  3. 10 core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php
  4. 10 core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php
  5. 9 core/modules/filter/src/Entity/FilterFormat.php
  6. 9 core/modules/filter/src/Plugin/DataType/FilterFormat.php
  7. 9 core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php
  8. 9 core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php
  9. 8.9.x core/modules/filter/src/Entity/FilterFormat.php
  10. 8.9.x core/modules/filter/src/Plugin/DataType/FilterFormat.php
  11. 8.9.x core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php
  12. 8.9.x core/modules/filter/src/Plugin/migrate/source/d7/FilterFormat.php
  13. main core/modules/filter/src/Entity/FilterFormat.php
  14. main core/modules/filter/src/Plugin/DataType/FilterFormat.php
  15. main core/modules/filter/src/Plugin/migrate/source/d6/FilterFormat.php
  16. main 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\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\OptionsProviderInterface;
use Drupal\Core\TypedData\Plugin\DataType\StringData;
use Drupal\filter\FilterFormatInterface;
use Drupal\filter\FilterFormatRepositoryInterface;

/**
 * The filter format data type.
 */
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 $this->getFormatsAsOptions($account);
  }
  
  /**
   * {@inheritdoc}
   */
  public function getSettableValues(?AccountInterface $account = NULL) {
    return array_keys($this->getSettableOptions($account));
  }
  
  /**
   * {@inheritdoc}
   */
  public function getSettableOptions(?AccountInterface $account = NULL) {
    return $this->getFormatsAsOptions($account);
  }
  
  /**
   * Returns a list of filter format config entity labels keyed by their ID.
   *
   * @param \Drupal\Core\Session\AccountInterface|null $account
   *   (optional) The user account for which to filter the options. If omitted,
   *   all options are returned.
   *
   * @return array<string, \Drupal\filter\FilterFormatInterface>
   *   A list of filter format config entity labels keyed by their ID.
   */
  protected function getFormatsAsOptions(?AccountInterface $account = NULL) : array {
    $repository = \Drupal::service(FilterFormatRepositoryInterface::class);
    return array_map(fn(FilterFormatInterface $format): string|\Stringable => $format->label(), $account ? $repository->getFormatsForAccount($account) : $repository->getAllFormats());
  }

}

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.