Skip to content

Commit

Permalink
Use the little_helpers container to load the action loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
torotil committed May 7, 2020
1 parent 49d8f11 commit 3abc3cd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ before_script:
- php -d include_path=`pwd` -d sendmail_path=`which true` ~/.composer/vendor/bin/drush.php --yes core-quick-drupal --core=drupal-7.69 --profile=testing --no-server --db-url=mysql://root:@127.0.0.1/drupal --root=$root
- ln -s $repo $root/sites/all/modules/campaignion
- cd $root
- drush dl addressfield ctools date entity features field_type_language file_entity form_builder-7.x-2.0-alpha2 i18n little_helpers-2.0-alpha2 media oowizard paypal_payment psr0 redhen references webform webform_confirm_email webform_template ultimate_cron
- drush dl addressfield ctools date entity features field_type_language file_entity form_builder-7.x-2.0-alpha2 i18n little_helpers-2.0-alpha10 media oowizard paypal_payment psr0 redhen references webform webform_confirm_email webform_template ultimate_cron
- drush --yes pm-enable campaignion_test

script:
Expand Down
2 changes: 1 addition & 1 deletion campaignion_action/campaignion_action.info
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ core = 7.x
package = Campaignion

dependencies[] = campaignion
dependencies[] = little_helpers (>=2.0-alpha1)
dependencies[] = little_helpers (>=2.0-alpha10)
dependencies[] = psr0
dependencies[] = webform_template
11 changes: 11 additions & 0 deletions campaignion_action/campaignion_action.module
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ use Drupal\campaignion\CRM\Import\Source\WebformSubmission;
use Drupal\little_helpers\System\FormRedirect;
use Drupal\little_helpers\Webform\Submission;

/**
* Implements hook_little_helpers_services().
*/
function campaignion_action_little_helpers_services() {
$info['campaignion_action.loader'] = [
'class' => Loader::class,
'constructor' => 'fromGlobalInfo',
];
return $info;
}

/**
* Implements hook_menu().
*/
Expand Down
16 changes: 3 additions & 13 deletions campaignion_action/src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\campaignion_action;

use Drupal\little_helpers\Services\Container;

/**
* Class for loading Action-Type plugins and general dependency injection.
*/
Expand All @@ -10,23 +12,11 @@ class Loader {
protected $info;
protected $types = [];

/**
* Inject a custom loader instance.
*
* NOTE: Only for testing purposes.
*/
public static function injectInstance($instance) {
static::$instance = $instance;
}

/**
* Get a singleton instance of this class.
*/
public static function instance() {
if (!static::$instance) {
static::$instance = static::fromGlobalInfo();
}
return static::$instance;
return Container::get()->loadService('campaignion_action.loader');
}

public static function fromGlobalInfo() {
Expand Down
5 changes: 3 additions & 2 deletions campaignion_email_to_target/tests/Wizard/FormStepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\campaignion_email_to_target\Action;
use Drupal\form_builder\Loader as FormBuilderLoader;
use Drupal\little_helpers\Rest\HttpError;
use Drupal\little_helpers\Services\Container;
use Upal\DrupalUnitTestCase;

/**
Expand All @@ -21,7 +22,7 @@ public function setUp() {
$mock_loader = $this->getMockBuilder(Loader::class)
->disableOriginalConstructor()
->getMock();
Loader::injectInstance($mock_loader);
Container::get()->inject('campaignion_action.loader', $mock_loader);
$mock_action = $this->getMockBuilder(Action::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -61,7 +62,7 @@ public function tearDown() {
node_delete($this->node->nid);
drupal_static_reset('form_set_error');
$_SESSION['messages'] = [];
Loader::injectInstance(NULL);
Container::get()->inject('campaignion_action.loader', NULL);
parent::tearDown();
}

Expand Down

0 comments on commit 3abc3cd

Please sign in to comment.