本文整理汇总了PHP中options_allowed_values函数的典型用法代码示例。如果您正苦于以下问题:PHP options_allowed_values函数的具体用法?PHP options_allowed_values怎么用?PHP options_allowed_values使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了options_allowed_values函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* 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: init
/**
* {@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);
}
示例3: testOptionsAllowedValues
/**
* 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);
}
示例4: generateValues
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;
}
示例5: viewElements
/**
* {@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: init
/**
* {@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: getSettableOptions
/**
* {@inheritdoc}
*/
public function getSettableOptions(AccountInterface $account = NULL)
{
$allowed_options = options_allowed_values($this->getFieldDefinition(), $this->getEntity());
return $allowed_options;
}
示例8: generateSampleValue
/**
* {@inheritdoc}
*/
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$allowed_options = options_allowed_values($field_definition->getFieldStorageDefinition());
$values['value'] = array_rand($allowed_options);
return $values;
}
示例9: init
/**
* {@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: getOptionsAllowedValues
/**
* 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());
}