class HideIfAuthor in Field Formatter Condition 8
The plugin for check empty fields.
Plugin annotation
@FieldFormatterCondition(
id = "hide_if_author",
label = @Translation("Hide if content from author"),
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\HideIfAuthor
- class \Drupal\fico\Plugin\FieldFormatterConditionBase implements FieldFormatterConditionInterface
Expanded class hierarchy of HideIfAuthor
File
- src/
Plugin/ Field/ FieldFormatter/ Condition/ HideIfAuthor.php, line 19
Namespace
Drupal\fico\Plugin\Field\FieldFormatter\ConditionView source
class HideIfAuthor extends FieldFormatterConditionBase {
/**
* {@inheritdoc}
*/
public function alterForm(&$form, $settings) {
if (isset($settings['settings']['author'])) {
$user = User::load($settings['settings']['author']);
}
else {
$user = NULL;
}
$config = \Drupal::config('user.settings');
$form['author'] = array(
'#title' => t('Authored by'),
'#type' => 'entity_autocomplete',
'#target_type' => 'user',
'#selection_settings' => [
'include_anonymous' => FALSE,
],
'#description' => t('Leave blank for %anonymous.', [
'%anonymous' => $config
->get('anonymous'),
]),
'#default_value' => $user,
);
}
/**
* {@inheritdoc}
*/
public function access(&$build, $field, $settings) {
$entity = $this
->getEntity($build);
if (!$entity) {
$build[$field]['#access'] = FALSE;
return;
}
if (!$settings['settings']['author'] && $entity
->getOwnerId() == 0 || $entity
->getOwnerId() == $settings['settings']['author']) {
$build[$field]['#access'] = FALSE;
}
}
/**
* {@inheritdoc}
*/
public function summary($settings) {
if (isset($settings['settings']['author'])) {
$user = User::load($settings['settings']['author']);
$user = $user
->getUsername();
}
else {
$config = \Drupal::config('user.settings');
$user = $config
->get('anonymous');
}
return t("Condition: %condition (%settings)", [
"%condition" => t('Hide if content from author'),
'%settings' => $user,
]);
}
}
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:: |
|
HideIfAuthor:: |
public | function |
Access control function. Overrides FieldFormatterConditionBase:: |
|
HideIfAuthor:: |
public | function |
Alter the condition form. Overrides FieldFormatterConditionBase:: |
|
HideIfAuthor:: |
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 |