LionsAd / service_container

Service Container Module on drupal.org - used for development and automated testing via travis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

service_container 1.0-beta3 release note proposal.

drupol opened this issue · comments

Security:

  • Issue #2508654 fixed, see details on drupal.org: Service Container was not affected directly, only custom modules depending on that file (Drupal/Component/Transliteration/PhpTransliteration.php) could have been vulnerable.

New features:

  • Submodule: service_container_annotation_discovery to declare plugins using annotations.
  • Plugins can now be constructed the same way as in Drupal 8.

New features documentation:

service_container_annotation_discovery:

This discovery module will use the doctrine annotation system to discover plugins.
How to get your plugin discovered automatically ?

  • Add a dependency to service_container_annotation_discovery in the info file of your module.
  • Create a file: yourmodule.services.yml:
parameters:
  annotated_plugins_auto_discovery:
    - { owner: 'plugin.manager', type: 'block', directory: 'Plugin/Block', class: 'Drupal\Core\Block\Annotation\Block' }

Parameters details:
owner: The owner of the plugins, usually your module name. In Drupal 8 the convention is to use simply 'plugin.manager', but then your type should be unique, e.g. commerce_plugin.
type: The type of plugin
directory: Where to find your plugin files, relative to [each-module-name]/src. No trailing slashes.
class: The class used for your annotations. (optional)

  • Create a plugin, create a file: [your_module]/src/Plugin/Block/YourChosenNameBlock.php:
<?php
/**
 * @file
 * Contains \Drupal\your_module\Plugin\Block\YourChosenNameBlock.
 */
namespace Drupal\your_module\Plugin\Block;
use Drupal\Component\Annotation\Plugin;
/**
 * Defines a Drupal Block.
 *
 * @Block(
 *   id = "YourChosenNameBlock",
 *   admin_label = "Your Module admin label",
 *   label = "Your Module chosen label Block",
 *   category = "Utility"
 * )
 */
class YourChosenNameBlock {
  /**
   * {@inheritdoc}
   */
  public function build() {
    return 'Hello World !';
  }
}
?>
  • Empty the cache
  • Use your plugin everywhere using:
\Drupal::service('plugin.manager.block')->createInstance('YourChosenNameBlock');

( This last part is subject to change still as we want to enable modules to use static constructors as well. )

  • Profit.

Drupal 8 style plugins

Plugins are now extending the Drupal 8 plugin base class: lib/Drupal/Component/Plugin/PluginBase.php
It means that the constructor of these plugins must be updated to match the requierements:

  /**
   * Constructs a Drupal\Component\Plugin\PluginBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {}

Bug fixes:

  • Errors related to alias handling and PhpArrayDumper are gone.
  • Drupal 8 component update
  • Add StringTranslationWrapper
  • Documentation update
  • Add some missing tests
  • Add methods documentation in Drupal 7 Legacy service
  • README.md and HACK.md update
  • Submodules files structure reorganization.

Closed pull requests: