class HideIfBoolCheck in Field Formatter Condition 8
The plugin for check empty fields.
Plugin annotation
@FieldFormatterCondition(
id = "hide_if_bool_check",
label = @Translation("Hide if checkbox is checked"),
dsFields = TRUE,
types = {
"all"
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\fico\Plugin\FieldFormatterConditionBase implements FieldFormatterConditionInterface
- class \Drupal\fico\Plugin\Field\FieldFormatter\Condition\HideIfBoolCheck
- class \Drupal\fico\Plugin\FieldFormatterConditionBase implements FieldFormatterConditionInterface
Expanded class hierarchy of HideIfBoolCheck
File
- src/
Plugin/ Field/ FieldFormatter/ Condition/ HideIfBoolCheck.php, line 18
Namespace
Drupal\fico\Plugin\Field\FieldFormatter\ConditionView source
class HideIfBoolCheck extends FieldFormatterConditionBase {
/**
* {@inheritdoc}
*/
public function alterForm(&$form, $settings) {
$options = [];
$fields = $this
->getEntityFields($settings['entity_type'], $settings['bundle']);
foreach ($fields as $field_name => $field) {
if ($field_name != $settings['field_name'] && $field
->getType() == 'boolean') {
$options[$field_name] = $field
->getLabel();
}
}
$default_target_field = isset($settings['settings']['target_field']) ? $settings['settings']['target_field'] : NULL;
$form['target_field'] = [
'#type' => 'select',
'#title' => t('Field'),
'#options' => $options,
'#default_value' => $default_target_field,
'#required' => TRUE,
];
$default_negate = isset($settings['settings']['negate']) ? $settings['settings']['negate'] : NULL;
$form['negate'] = [
'#type' => 'checkbox',
'#title' => t('Negate'),
'#description' => t('If checked, the condition result is negated such that it returns TRUE if it evaluates to FALSE.'),
'#default_value' => $default_negate,
];
}
/**
* {@inheritdoc}
*/
public function access(&$build, $field, $settings) {
if (!($entity = $this
->getEntity($build))) {
$build[$field]['#access'] = FALSE;
return;
}
$items = $entity
->get($settings['settings']['target_field']);
foreach ($items as $key => $item) {
$value = $item
->getValue();
if (empty($settings['settings']['negate']) && !empty($value['value']) || !empty($settings['settings']['negate']) && empty($value['value'])) {
$build[$field]['#access'] = FALSE;
}
}
}
/**
* {@inheritdoc}
*/
public function summary($settings) {
$options = [];
$fields = $this
->getEntityFields($settings['entity_type'], $settings['bundle']);
foreach ($fields as $field_name => $field) {
if ($field_name != $settings['field_name']) {
$options[$field_name] = $field
->getLabel();
}
}
$not = $settings['settings']['negate'] ? sprintf(' %s', t('not')) : '';
return t("Condition: %condition (%settings)", [
"%condition" => t('Hide if checkbox is%not checked', [
'%not' => $not,
]),
'%settings' => $options[$settings['settings']['target_field']],
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldFormatterConditionBase:: |
public | function |
Creates a pre-configured instance of a plugin. Overrides FactoryInterface:: |
|
FieldFormatterConditionBase:: |
public | function |
Gets a specific plugin definition. Overrides DiscoveryInterface:: |
|
FieldFormatterConditionBase:: |
public | function |
Gets the definition of all plugins for this type. Overrides DiscoveryInterface:: |
|
FieldFormatterConditionBase:: |
protected | function | Check for entity in build. | |
FieldFormatterConditionBase:: |
protected | function | Load fields from a entity. | |
FieldFormatterConditionBase:: |
protected | function | Check for entity_type in build. | |
FieldFormatterConditionBase:: |
public | function |
Gets a preconfigured instance of a plugin. Overrides MapperInterface:: |
|
FieldFormatterConditionBase:: |
public | function |
Indicates if a specific plugin definition exists. Overrides DiscoveryInterface:: |
|
HideIfBoolCheck:: |
public | function |
Access control function. Overrides FieldFormatterConditionBase:: |
|
HideIfBoolCheck:: |
public | function |
Alter the condition form. Overrides FieldFormatterConditionBase:: |
|
HideIfBoolCheck:: |
public | function |
Return the summary string. Overrides FieldFormatterConditionBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |