getSettableValues example

'filtered_html' => 'Filtered HTML',
      'full_html' => 'Full HTML',
      '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.');
    
$field_definition->setSetting('handler_settings', $handler_settings);
    }
    $changed |= $bundles_changed;

    return $changed;
  }

  /** * {@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 __construct(AccountInterface $current_user) {
    $this->currentUser = $current_user;
  }

  /** * {@inheritdoc} */
  public function validate($value, Constraint $constraint) {
    $typed_data = $this->getTypedData();

    if ($typed_data instanceof OptionsProviderInterface) {
      $allowed_values = $typed_data->getSettableValues($this->currentUser);
      $constraint->choices = $allowed_values;

      // If the data is complex, we have to validate its main property.       if ($typed_data instanceof ComplexDataInterface) {
        $name = $typed_data->getDataDefinition()->getMainPropertyName();
        if (!isset($name)) {
          throw new \LogicException('Cannot validate allowed values for complex data without a main property.');
        }
        $typed_data = $typed_data->get($name);
        $value = $typed_data->getValue();
      }
    }
Home | Imprint | This part of the site doesn't use cookies.