class MachineName
Same name in this branch
- 9 core/modules/migrate/src/Plugin/migrate/process/MachineName.php \Drupal\migrate\Plugin\migrate\process\MachineName
- 9 core/lib/Drupal/Core/Render/Element/MachineName.php \Drupal\Core\Render\Element\MachineName
Same name and namespace in other branches
- 11.x core/modules/views/src/Plugin/views/field/MachineName.php \Drupal\views\Plugin\views\field\MachineName
- 11.x core/modules/migrate/src/Plugin/migrate/process/MachineName.php \Drupal\migrate\Plugin\migrate\process\MachineName
- 11.x core/lib/Drupal/Core/Render/Element/MachineName.php \Drupal\Core\Render\Element\MachineName
- 10 core/modules/views/src/Plugin/views/field/MachineName.php \Drupal\views\Plugin\views\field\MachineName
- 10 core/modules/migrate/src/Plugin/migrate/process/MachineName.php \Drupal\migrate\Plugin\migrate\process\MachineName
- 10 core/lib/Drupal/Core/Render/Element/MachineName.php \Drupal\Core\Render\Element\MachineName
- 8.9.x core/modules/views/src/Plugin/views/field/MachineName.php \Drupal\views\Plugin\views\field\MachineName
- 8.9.x core/modules/migrate/src/Plugin/migrate/process/MachineName.php \Drupal\migrate\Plugin\migrate\process\MachineName
- 8.9.x core/lib/Drupal/Core/Render/Element/MachineName.php \Drupal\Core\Render\Element\MachineName
Field handler which allows to show machine name content as human name.
Definition items:
- options callback: The function to call in order to generate the value options. If omitted, the options 'Yes' and 'No' will be used.
- options arguments: An array of arguments to pass to the options callback.
Plugin annotation
@ViewsField("machine_name");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase implements \Drupal\views\Plugin\views\field\FieldHandlerInterface extends \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\field\MachineName extends \Drupal\views\Plugin\views\field\FieldPluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase implements \Drupal\views\Plugin\views\field\FieldHandlerInterface extends \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of MachineName
Related topics
4 string references to 'MachineName'
- BlockTemplateSuggestionsTest::testBlockThemeHookSuggestions in core/
modules/ block/ tests/ src/ Kernel/ BlockTemplateSuggestionsTest.php - Tests template suggestions from block_theme_suggestions_block().
- SystemMenuBlockTest::testConfigExpanded in core/
modules/ system/ tests/ src/ Kernel/ Block/ SystemMenuBlockTest.php - Tests the config expanded option.
- SystemMenuBlockTest::testConfigLevelDepth in core/
modules/ system/ tests/ src/ Kernel/ Block/ SystemMenuBlockTest.php - Tests the config start level and depth.
- SystemMenuBlockTest::testSystemMenuBlockConfigDependencies in core/
modules/ system/ tests/ src/ Kernel/ Block/ SystemMenuBlockTest.php - Tests calculation of a system menu block's configuration dependencies.
File
-
core/
modules/ views/ src/ Plugin/ views/ field/ MachineName.php, line 18
Namespace
Drupal\views\Plugin\views\fieldView source
class MachineName extends FieldPluginBase {
/**
* Stores the available options.
*
* @var array
*/
protected $valueOptions;
public function getValueOptions() {
if (isset($this->valueOptions)) {
return;
}
if (isset($this->definition['options callback']) && is_callable($this->definition['options callback'])) {
if (isset($this->definition['options arguments']) && is_array($this->definition['options arguments'])) {
$this->valueOptions = call_user_func_array($this->definition['options callback'], $this->definition['options arguments']);
}
else {
$this->valueOptions = call_user_func($this->definition['options callback']);
}
}
else {
$this->valueOptions = [];
}
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['machine_name'] = [
'default' => FALSE,
];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['machine_name'] = [
'#title' => $this->t('Output machine name'),
'#description' => $this->t('Display field as machine name.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['machine_name']),
];
}
/**
* {@inheritdoc}
*/
public function preRender(&$values) {
$this->getValueOptions();
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$value = $values->{$this->field_alias};
if (!empty($this->options['machine_name']) || !isset($this->valueOptions[$value])) {
$result = $this->sanitizeValue($value);
}
else {
$result = $this->valueOptions[$value];
}
return $result;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.