class ExampleHamSandwich in Examples for Developers 3.x
Same name and namespace in other branches
- 8 plugin_type_example/src/Plugin/Sandwich/ExampleHamSandwich.php \Drupal\plugin_type_example\Plugin\Sandwich\ExampleHamSandwich
Provides a ham sandwich.
Because the plugin manager class for our plugins uses annotated class discovery, our meatball sandwich only needs to exist within the Plugin\Sandwich namespace, and provide a Sandwich annotation to be declared as a plugin. This is defined in \Drupal\plugin_type_example\SandwichPluginManager::__construct().
The following is the plugin annotation. This is parsed by Doctrine to make the plugin definition. Any values defined here will be available in the plugin definition.
This should be used for metadata that is specifically required to instantiate the plugin, or for example data that might be needed to display a list of all available plugins where the user selects one. This means many plugin annotations can be reduced to a plugin ID, a label and perhaps a description.
Plugin annotation
@Sandwich(
id = "ham_sandwich",
description = @Translation("Ham, mustard, rocket, sun-dried tomatoes."),
calories = 426
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\plugin_type_example\SandwichBase implements SandwichInterface
- class \Drupal\plugin_type_example\Plugin\Sandwich\ExampleHamSandwich
- class \Drupal\plugin_type_example\SandwichBase implements SandwichInterface
Expanded class hierarchy of ExampleHamSandwich
1 file declares its use of ExampleHamSandwich
- PluginTypeExampleTest.php in modules/
plugin_type_example/ tests/ src/ Functional/ PluginTypeExampleTest.php
File
- modules/
plugin_type_example/ src/ Plugin/ Sandwich/ ExampleHamSandwich.php, line 31
Namespace
Drupal\plugin_type_example\Plugin\SandwichView source
class ExampleHamSandwich extends SandwichBase {
/**
* Place an order for a sandwich.
*
* This is just an example method on our plugin that we can call to get
* something back.
*
* @param array $extras
* Array of extras to include with this order.
*
* @return string
* A description of the sandwich ordered.
*/
public function order(array $extras) {
$ingredients = [
'ham, mustard',
'rocket',
'sun-dried tomatoes',
];
$sandwich = array_merge($ingredients, $extras);
return 'You ordered an ' . implode(', ', $sandwich) . ' sandwich. Enjoy!';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExampleHamSandwich:: |
public | function |
Place an order for a sandwich. Overrides SandwichBase:: |
|
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:: |
2 |
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. | 98 |
SandwichBase:: |
public | function |
Provide the number of calories per serving for the sandwich. Overrides SandwichInterface:: |
|
SandwichBase:: |
public | function |
Provide a description of the sandwich. Overrides SandwichInterface:: |
1 |