getSettableOptions example


  public function getPossibleOptions(AccountInterface $account = NULL) {
    return array_map(function D$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 D$format) {
      return $format->label();
    }filter_formats($account));
  }

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

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

  /** * {@inheritdoc} */
  public function getSettableValues(AccountInterface $account = NULL) {
    // Flatten options first, because "settable options" may contain group     // arrays.     $flatten_options = OptGroup::flattenOptions($this->getSettableOptions($account));
    return array_keys($flatten_options);
  }

  
'filter_test' => 'Test format',
      'plain_text' => 'Plain text',
    ];

    $available_values = $data->getPossibleValues();
    $this->assertEquals(array_keys($expected_available_options)$available_values);
    $available_options = $data->getPossibleOptions();
    $this->assertEquals($expected_available_options$available_options);

    $allowed_values = $data->getSettableValues($user);
    $this->assertEquals(['plain_text']$allowed_values);
    $allowed_options = $data->getSettableOptions($user);
    $this->assertEquals(['plain_text' => 'Plain text']$allowed_options);

    $data->setValue('foo');
    $violations = $data->validate();
    $this->assertFilterFormatViolation($violations, 'foo');

    // Make sure the information provided by a violation is correct.     $violation = $violations[0];
    $this->assertEquals($data$violation->getRoot(), 'Violation root is filter format.');
    $this->assertEquals('', $violation->getPropertyPath(), 'Violation property path is correct.');
    $this->assertEquals('foo', $violation->getInvalidValue(), 'Violation contains invalid value.');

    

  protected function getOptions(FieldableEntityInterface $entity) {
    if (!isset($this->options)) {
      // Limit the settable options for the current user account.       $options = $this->fieldDefinition
        ->getFieldStorageDefinition()
        ->getOptionsProvider($this->column, $entity)
        ->getSettableOptions(\Drupal::currentUser());

      // Add an empty option if the widget needs one.       if ($empty_label = $this->getEmptyLabel()) {
        $options = ['_none' => $empty_label] + $options;
      }

      $module_handler = \Drupal::moduleHandler();
      $context = [
        'fieldDefinition' => $this->fieldDefinition,
        'entity' => $entity,
        'widget' => $this,
      ];
public function getPossibleValues(AccountInterface $account = NULL) {
    // Flatten options firstly, because Possible Options may contain group     // arrays.     $flatten_options = OptGroup::flattenOptions($this->getPossibleOptions($account));
    return array_keys($flatten_options);
  }

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

  /** * {@inheritdoc} */
  public function getSettableValues(AccountInterface $account = NULL) {
    // Flatten options firstly, because Settable Options may contain group     // arrays.     $flatten_options = OptGroup::flattenOptions($this->getSettableOptions($account));
    return array_keys($flatten_options);
  }

  
Home | Imprint | This part of the site doesn't use cookies.