class HideOnPages in Field Formatter Condition 8
The plugin for check empty fields.
Plugin annotation
@FieldFormatterCondition(
id = "hide_on_pages",
label = @Translation("Hide on specific pages"),
dsFields = FALSE,
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\HideOnPages
- class \Drupal\fico\Plugin\FieldFormatterConditionBase implements FieldFormatterConditionInterface
Expanded class hierarchy of HideOnPages
File
- src/
Plugin/ Field/ FieldFormatter/ Condition/ HideOnPages.php, line 18
Namespace
Drupal\fico\Plugin\Field\FieldFormatter\ConditionView source
class HideOnPages extends FieldFormatterConditionBase {
/**
* {@inheritdoc}
*/
public function alterForm(&$form, $settings) {
$default_visibility = isset($settings['settings']['visibility']) ? $settings['settings']['visibility'] : 0;
$default_pages = isset($settings['settings']['pages']) ? $settings['settings']['pages'] : '';
$form['visibility'] = array(
'#title' => t('Type of display'),
'#type' => 'radios',
'#options' => array(
0 => t('All pages except those listed'),
1 => t('Only the listed pages'),
),
'#default_value' => $default_visibility,
);
$form['pages'] = array(
'#type' => 'textarea',
'#title' => t('Enter pages'),
'#cols' => 10,
'#default_value' => $default_pages,
'#description' => t("Specify pages by using their paths. Enter one path per line. * is used as wildcard."),
);
}
/**
* {@inheritdoc}
*/
public function access(&$build, $field, $settings) {
$path = \Drupal::service('path.current')
->getPath();
$path = $path[0] == '/' ? substr($path, 1) : $path;
$page_match = \Drupal::service('path.matcher')
->matchPath($path, $settings['settings']['pages']);
$page_match = !($settings['settings']['visibility'] xor $page_match);
if ($page_match) {
$build[$field]['#access'] = FALSE;
}
}
/**
* {@inheritdoc}
*/
public function summary($settings) {
$pages = explode("\n", $settings['settings']['pages']);
return t("Condition: %condition - %visibility (%settings)", [
"%condition" => t('Hide on specific pages'),
"%visibility" => $settings['settings']['visibility'] == 1 ? t('Only the listed pages') : t('All pages except those listed'),
"%settings" => implode(', ', $pages),
]);
}
}
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:: |
|
HideOnPages:: |
public | function |
Access control function. Overrides FieldFormatterConditionBase:: |
|
HideOnPages:: |
public | function |
Alter the condition form. Overrides FieldFormatterConditionBase:: |
|
HideOnPages:: |
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 |