You are here

interface SandwichInterface in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/plugin_type_example/src/SandwichInterface.php \Drupal\plugin_type_example\SandwichInterface

An interface for all Sandwich type plugins.

When defining a new plugin type you need to define an interface that all plugins of the new type will implement. This ensures that consumers of the plugin type have a consistent way of accessing the plugin's functionality. It should include access to any public properties, and methods for accomplishing whatever business logic anyone accessing the plugin might want to use.

For example, an image manipulation plugin might have a "process" method that takes a known input, probably an image file, and returns the processed version of the file.

In our case we'll define methods for accessing the human readable description of a sandwich and the number of calories per serving. As well as a method for ordering a sandwich.

Hierarchy

Expanded class hierarchy of SandwichInterface

All classes that implement SandwichInterface

File

plugin_type_example/src/SandwichInterface.php, line 22

Namespace

Drupal\plugin_type_example
View source
interface SandwichInterface {

  /**
   * Provide a description of the sandwich.
   *
   * @return string
   *   A string description of the sandwich.
   */
  public function description();

  /**
   * Provide the number of calories per serving for the sandwich.
   *
   * @return float
   *   The number of calories per serving.
   */
  public function calories();

  /**
   * 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
   *   An array of extra ingredients to include with this sandwich.
   *
   * @return string
   *   Description of the sandwich that was just ordered.
   */
  public function order(array $extras);

}

Members

Namesort descending Modifiers Type Description Overrides
SandwichInterface::calories public function Provide the number of calories per serving for the sandwich. 1
SandwichInterface::description public function Provide a description of the sandwich. 1
SandwichInterface::order public function Place an order for a sandwich. 1