class ExampleNodeLabel in Extra Field Settings Provider 8
Same name and namespace in other branches
- 8.2 modules/extra_field_plus_example/src/Plugin/ExtraField/Display/ExampleNodeLabel.php \Drupal\extra_field_plus_example\Plugin\ExtraField\Display\ExampleNodeLabel
Example Extra field Display.
Plugin annotation
@ExtraFieldDisplay(
id = "example_node_label",
label = @Translation("Example Node Label"),
bundles = {
"node.*"
},
visible = false
)
Hierarchy
- class \Drupal\extra_field_plus\Plugin\ExtraFieldPlusDisplayBase extends \Drupal\extra_field\Plugin\ExtraFieldDisplayBase implements ExtraFieldPlusDisplayInterface uses StringTranslationTrait
- class \Drupal\extra_field_plus_example\Plugin\ExtraField\Display\ExampleNodeLabel
Expanded class hierarchy of ExampleNodeLabel
File
- modules/
extra_field_plus_example/ src/ Plugin/ ExtraField/ Display/ ExampleNodeLabel.php, line 20
Namespace
Drupal\extra_field_plus_example\Plugin\ExtraField\DisplayView source
class ExampleNodeLabel extends ExtraFieldPlusDisplayBase {
/**
* {@inheritdoc}
*/
public function view(ContentEntityInterface $entity) {
$settings = $this
->getSettings();
$link_to_entity = $settings['link_to_entity'];
$wrapper = $settings['wrapper'];
$label = $entity
->label();
$url = NULL;
if ($link_to_entity) {
$url = $entity
->toUrl()
->setAbsolute();
}
if ($url) {
$element = [
'#type' => 'html_tag',
'#tag' => $wrapper,
[
'#type' => 'link',
'#title' => $label,
'#url' => $url,
],
];
}
else {
$element = [
'#type' => 'html_tag',
'#tag' => $wrapper,
'#value' => $label,
];
}
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsForm() {
$form = parent::settingsForm();
$form['link_to_entity'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Link to the entity'),
];
$form['wrapper'] = [
'#type' => 'select',
'#title' => $this
->t('Wrapper'),
'#options' => [
'span' => 'span',
'p' => 'p',
'h1' => 'h1',
'h2' => 'h2',
'h3' => 'h3',
'h4' => 'h4',
'h5' => 'h5',
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function defaultFormValues() {
$values = parent::defaultFormValues();
$values += [
'link_to_entity' => FALSE,
'wrapper' => 'span',
];
return $values;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExampleNodeLabel:: |
public | function |
Provides field settings form default values. Overrides ExtraFieldPlusDisplayBase:: |
|
ExampleNodeLabel:: |
public | function |
Provides field settings form. Overrides ExtraFieldPlusDisplayBase:: |
|
ExampleNodeLabel:: |
public | function | ||
ExtraFieldPlusDisplayBase:: |
public | function |
Returns field settings form default values. Overrides ExtraFieldPlusDisplayInterface:: |
|
ExtraFieldPlusDisplayBase:: |
public | function |
Returns field setting. Overrides ExtraFieldPlusDisplayInterface:: |
|
ExtraFieldPlusDisplayBase:: |
public | function |
Returns field settings. Overrides ExtraFieldPlusDisplayInterface:: |
|
ExtraFieldPlusDisplayBase:: |
public | function |
Returns field settings form. Overrides ExtraFieldPlusDisplayInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |