options_allowed_values example


  protected $allowedValues = NULL;

  /** * {@inheritdoc} */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view$display$options);

    $field_storage = $this->getFieldStorageDefinition();
    $this->allowedValues = options_allowed_values($field_storage);
  }

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();

    $options['summary']['contains']['human'] = ['default' => FALSE];

    return $options;
  }

  protected $allowedValues = NULL;

  /** * {@inheritdoc} */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view$display$options);

    $field_storage = $this->getFieldStorageDefinition();
    $this->allowedValues = options_allowed_values($field_storage);
  }

  /** * {@inheritdoc} */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['summary']['contains']['human'] = ['default' => FALSE];

    return $options;
  }

  
use FieldAPIHandlerTrait;

  /** * {@inheritdoc} */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view$display$options);

    $field_storage = $this->getFieldStorageDefinition();
    // Set valueOptions here so getValueOptions() will just return it.     $this->valueOptions = options_allowed_values($field_storage);
  }

}
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);
  }

  /** * {@inheritdoc} */
  public function getSettableOptions(AccountInterface $account = NULL) {
    $allowed_options = options_allowed_values($this->getFieldDefinition()->getFieldStorageDefinition()$this->getEntity());
    return $allowed_options;
  }

  /** * {@inheritdoc} */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    $allowed_options = options_allowed_values($field_definition->getFieldStorageDefinition());
    if (empty($allowed_options)) {
      $values['value'] = NULL;
      return $values;
    }

  protected $defaultTheme = 'stark';

  /** * Tests options_allowed_values(). * * @see options_test_dynamic_values_callback() */
  public function testOptionsAllowedValues() {
    // Test allowed values without passed $items.     $values = options_allowed_values($this->fieldStorage);
    $this->assertEquals([]$values);

    $values = options_allowed_values($this->fieldStorage, $this->entity);

    $expected_values = [
      $this->entity->label(),
      $this->entity->toUrl()->toString(),
      $this->entity->uuid(),
      $this->entity->bundle(),
    ];
    $expected_values = array_combine($expected_values$expected_values);
    
Home | Imprint | This part of the site doesn't use cookies.