Пример #1
0
 /**
  * Overrides \Drupal\views\Plugin\views\argument\ArgumentPluginBase::init().
  */
 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
 {
     parent::init($view, $display, $options);
     $field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
     $field_storage = $field_storage_definitions[$this->definition['field_name']];
     $this->allowed_values = options_allowed_values($field_storage);
 }
Пример #2
0
 /**
  * {@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);
 }
 /**
  * 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->assertEqual([], $values);
     $values = options_allowed_values($this->fieldStorage, $this->entity);
     $expected_values = array($this->entity->label(), $this->entity->url(), $this->entity->uuid(), $this->entity->bundle());
     $expected_values = array_combine($expected_values, $expected_values);
     $this->assertEqual($expected_values, $values);
 }
 public function generateValues($object, $instance, $plugin_definition, $form_display_options)
 {
     $object_field = array();
     $field_info = Field::fieldInfo()->getFieldStorageDefinition($object->entityType(), $instance->getFieldName());
     if ($allowed_values = options_allowed_values($field_info, $object)) {
         $keys = array_keys($allowed_values);
         $object_field['value'] = $keys[mt_rand(0, count($allowed_values) - 1)];
     }
     return $object_field;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     $entity = $items->getEntity();
     $allowed_values = options_allowed_values($this->fieldDefinition, $entity);
     foreach ($items as $delta => $item) {
         if (isset($allowed_values[$item->value])) {
             $output = field_filter_xss($allowed_values[$item->value]);
         } else {
             // If no match was found in allowed values, fall back to the key.
             $output = field_filter_xss($item->value);
         }
         $elements[$delta] = array('#markup' => $output);
     }
     return $elements;
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
 {
     parent::init($view, $display, $options);
     $this->definition['field_name'] = $this->definition['entity field'];
     $field_storage = $this->getFieldStorageDefinition();
     // We may have not a valid workflow field.
     if (FALSE && $field_storage) {
         // Set valueOptions here so getValueOptions() will just return it.
         $this->valueOptions = options_allowed_values($field_storage);
         // $this->valueOptions = workflow_state_allowed_values($field_storage);
     } else {
         // TODO D8. This is a hack. It doesn't work.
         // The default options_allowed_values only reads field_name. Repair that.
         $field_name = $this->definition['entity field'];
         $field_storage = new FieldStorageConfig(['field_name' => $field_name, 'type' => 'testtype', 'entity_type' => $options['entity_type']]);
         $field_storage->set('allowed_values_function', 'workflow_state_allowed_values');
         $wid = '';
         // Set valueOptions here so getValueOptions() will just return it.
         // $this->valueOptions = options_allowed_values($field_storage);
         // $this->valueOptions = workflow_state_allowed_values($field_storage);
         $this->valueOptions = workflow_get_workflow_state_names($wid, $options['group_info']['widget'] == 'select');
     }
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function getSettableOptions(AccountInterface $account = NULL)
 {
     $allowed_options = options_allowed_values($this->getFieldDefinition(), $this->getEntity());
     return $allowed_options;
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
   $allowed_options = options_allowed_values($field_definition->getFieldStorageDefinition());
   $values['value'] = array_rand($allowed_options);
   return $values;
 }
 /**
  * {@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);
 }
Пример #10
0
 /**
  * Returns the array of allowed values for the Options email field.
  *
  * @return array
  *   An array of allowed values entered by the user, for the Options email
  *   field.
  */
 protected function getOptionsAllowedValues() {
   return options_allowed_values($this->getFieldDefinition()->getFieldStorageDefinition(), $this->getEntity());
 }