class HideDateTime in Field Formatter Condition 8
The plugin for check empty fields.
Plugin annotation
@FieldFormatterCondition(
id = "hide_date_time",
label = @Translation("Hide date/time"),
dsFields = TRUE,
types = {
"datetime",
"date",
"datestamp"
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\fico\Plugin\FieldFormatterConditionBase implements FieldFormatterConditionInterface
- class \Drupal\fico\Plugin\Field\FieldFormatter\Condition\HideDateTime
- class \Drupal\fico\Plugin\FieldFormatterConditionBase implements FieldFormatterConditionInterface
Expanded class hierarchy of HideDateTime
File
- src/
Plugin/ Field/ FieldFormatter/ Condition/ HideDateTime.php, line 20
Namespace
Drupal\fico\Plugin\Field\FieldFormatter\ConditionView source
class HideDateTime extends FieldFormatterConditionBase {
/**
* {@inheritdoc}
*/
public function alterForm(&$form, $settings) {
$default_orientation = isset($settings['settings']['orientation']) ? $settings['settings']['orientation'] : NULL;
$default_cutom_date = isset($settings['settings']['cutom_date']) ? $settings['settings']['cutom_date'] : NULL;
$form['orientation'] = [
'#title' => t('Hide if'),
'#type' => 'radios',
'#options' => array(
'smaller' => t("smaller than today's date"),
'greater' => t("greater than today's date"),
'custom_small' => t("smaller then custom date"),
'greater_small' => t("greater then custom date"),
),
'#default_value' => $default_orientation,
];
$form['cutom_date'] = [
'#title' => t('Cutom date'),
'#type' => 'date',
'#default_value' => $default_cutom_date,
];
}
/**
* {@inheritdoc}
*/
public function access(&$build, $field, $settings) {
$custom_date = strtotime($settings['settings']['cutom_date']);
if (!empty($build[$field]['#items'])) {
foreach ($build[$field]['#items'] as $item) {
$info = $item
->getValue($field);
switch ($settings['settings']['orientation']) {
case 'smaller':
if (strtotime($info['value']) < REQUEST_TIME) {
$build[$field]['#access'] = FALSE;
}
break;
case 'greater':
if (strtotime($info['value']) > REQUEST_TIME) {
$build[$field]['#access'] = FALSE;
}
break;
case 'custom_small':
if (strtotime($info['value']) < $custom_date) {
$build[$field]['#access'] = FALSE;
}
break;
case 'greater_small':
if (strtotime($info['value']) > $custom_date) {
$build[$field]['#access'] = FALSE;
}
break;
default:
$build[$field]['#access'] = FALSE;
}
}
}
if (empty($build[$field]['#items'])) {
$build[$field]['#access'] = FALSE;
}
}
/**
* {@inheritdoc}
*/
public function summary($settings) {
$orientations = array(
'smaller' => t("smaller than today's date"),
'greater' => t("greater than today's date"),
'custom_small' => t("smaller then custom date"),
'greater_small' => t("greater then custom date"),
);
if ($settings['settings']['orientation'] != 'smaller' && $settings['settings']['orientation'] != 'greater') {
$display_date = ' - ' . $settings['settings']['cutom_date'];
}
else {
$display_date = '';
}
return t('Condition: %condition (%orientation%date)', [
"%condition" => t('Hide date/time'),
'%orientation' => $orientations[$settings['settings']['orientation']],
'%date' => $display_date,
]);
}
}
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:: |
|
HideDateTime:: |
public | function |
Access control function. Overrides FieldFormatterConditionBase:: |
|
HideDateTime:: |
public | function |
Alter the condition form. Overrides FieldFormatterConditionBase:: |
|
HideDateTime:: |
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 |