protected function DefaultModuleHelper::setFactory

7.x-1.x DefaultModuleHelper.php protected DefaultModuleHelper::setFactory(IFactory $factory)

Sets the factory of this.

The module machine name of the provided factory must match the module machine name known to this.

Parameters

\Drupal\ooe\Factory\IFactory $factory: The factory.

Return value

\Drupal\ooe\Module\IModuleHelper This.

Throws

\Exception If $factory is empty or the module machine name of the factory is inconsistent.

1 call to DefaultModuleHelper::setFactory()
DefaultModuleHelper::__construct in lib/Drupal/ooe/Module/DefaultModuleHelper.php
Constructor.

File

lib/Drupal/ooe/Module/DefaultModuleHelper.php, line 153
DefaultModuleHelper

Class

DefaultModuleHelper
Classes that need to keep a record of the name of the module they serve may choose to extend this.

Namespace

Drupal\ooe\Module

Code

protected function setFactory(IFactory $factory) {
  if (empty($factory)) {
    throw new \Exception('IFactory $factory must not be empty !');
  }
  if ($factory->getModuleName() != $this->getModule()) {
    throw new Exception(
    'The module machine name(' . $factory->getModuleName() .
      ') of the provided factory does match' .
      'The module machine name(' . $this->getModule() . ') of this !'
      );
    // Coder: ERROR | String concat is not required here;
    // use a single string instead
    // Webel: Bug report: https://www.drupal.org/node/2305591
  }
  $this->factory = $factory;
  return $this;
}