You are here

interface FeaturesGeneratorInterface in Features 8.4

Same name and namespace in other branches
  1. 8.3 src/FeaturesGeneratorInterface.php \Drupal\features\FeaturesGeneratorInterface

Common interface for features generation services.

The configuration packaging API is based on two major concepts:

  • Packages: modules into which configuration is packaged.
  • Package generation methods: responsible for `determining which package to assign a given piece of configuration to.

Generation methods are customizable.

Features defines two package generation methods, which are simple plugin classes that implement a particular logic to assign pieces of configuration to a given package (module).

Modules can define additional package generation methods by simply providing the related plugins, and alter existing methods through hook_features_generation_method_info_alter(). Here is an example snippet:

function mymodule_features_generation_method_info_alter(&$generation_info) {

  // Replace the original plugin with our own implementation.
  $method_id = \Drupal\features\Plugin\FeaturesGeneration\FeaturesGenerationArchive::METHOD_ID;
  $generation_info[$method_id]['class'] = 'Drupal\\my_module\\Plugin\\FeaturesGeneration\\MyFeaturesGenerationArchive';
}
class MyFeaturesGenerationArchive extends FeaturesGenerationArchive {
  public function generate(array $packages = array(), FeaturesBundleInterface $bundle = NULL) {

    // Insert customization here.
  }

}
?>
?><?php

For more information, see Developing for Features 3.x

Hierarchy

Expanded class hierarchy of FeaturesGeneratorInterface

All classes that implement FeaturesGeneratorInterface

3 files declare their use of FeaturesGeneratorInterface
FeaturesCommands.php in src/Commands/FeaturesCommands.php
FeaturesEditForm.php in modules/features_ui/src/Form/FeaturesEditForm.php
FeaturesExportForm.php in modules/features_ui/src/Form/FeaturesExportForm.php

File

src/FeaturesGeneratorInterface.php, line 42

Namespace

Drupal\features
View source
interface FeaturesGeneratorInterface {

  /**
   * The package generation method id for the package generator itself.
   */
  const METHOD_ID = 'generator-default';

  /**
   * Resets the assigned packages and the method instances.
   */
  public function reset();

  /**
   * Apply a given package generation method.
   *
   * @param string $method_id
   *   The string identifier of the package generation method to use to package
   *   configuration.
   * @param array $packages
   *   Array of package data.
   * @param \Drupal\features\FeaturesBundleInterface $bundle
   *   The optional bundle used for the generation.  Used to generate profiles.
   *
   * @return array
   *   Array of results for profile and/or packages, each result including the
   *   following keys:
   *   - 'success': boolean TRUE or FALSE for successful writing.
   *   - 'display': boolean TRUE if the message should be displayed to the
   *     user, otherwise FALSE.
   *   - 'message': a message about the result of the operation.
   *   - 'variables': an array of substitutions to be used in the message.
   */
  public function applyGenerationMethod($method_id, array $packages = [], FeaturesBundleInterface $bundle = NULL);

  /**
   * Responds to the submission of
   * \Drupal\features_ui\Form\FeaturesExportForm.
   */
  public function applyExportFormSubmit($method_id, &$form, FormStateInterface $form_state);

  /**
   * Returns the enabled package generation methods.
   *
   * @return array
   *   An array of package generation method definitions keyed by method id.
   */
  public function getGenerationMethods();

  /**
   * Generates file representations of configuration packages.
   *
   * @param string $method_id
   *   The ID of the generation method to use.
   * @param \Drupal\features\FeaturesBundleInterface $bundle
   *   The bundle used for the generation.
   * @param array $package_names
   *   Array of names of packages to be generated. If none are specified, all
   *   available packages will be added.
   */
  public function generatePackages($method_id, FeaturesBundleInterface $bundle, array $package_names = []);

}

Members

Namesort descending Modifiers Type Description Overrides
FeaturesGeneratorInterface::applyExportFormSubmit public function Responds to the submission of \Drupal\features_ui\Form\FeaturesExportForm. 1
FeaturesGeneratorInterface::applyGenerationMethod public function Apply a given package generation method. 1
FeaturesGeneratorInterface::generatePackages public function Generates file representations of configuration packages. 1
FeaturesGeneratorInterface::getGenerationMethods public function Returns the enabled package generation methods. 1
FeaturesGeneratorInterface::METHOD_ID constant The package generation method id for the package generator itself.
FeaturesGeneratorInterface::reset public function Resets the assigned packages and the method instances. 1