-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Milkovsky feature/rul 44 #430
Open
fago
wants to merge
39
commits into
8.x-3.x
Choose a base branch
from
milkovsky-feature/RUL-44
base: 8.x-3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
ddddfd2
Added EventHandlerEntityBundle.
milkovsky 52317fd
Added EventHandlerEntityBundle to events yml.
milkovsky b60b780
Started writing EventHandlerTest. WIP.
milkovsky 753833d
EventHandlerTest WIP.
milkovsky 46f1fbe
Improved EventHandlerTest WIP.
milkovsky 066e4ec
PR fixes.
milkovsky 0f1a9e5
Dispatch events by base name of a configured event name.
milkovsky ecce557
Implemented testEntityBundleHandlerExecution.
milkovsky 54c3cd4
PR fixes.
milkovsky 03ecf3a
PR fixes.
milkovsky 7fbae65
PR fixes.
milkovsky 8e4af1b
PR fixes.
milkovsky b57e33d
Change rules config to have multiple events.
milkovsky 7d0d7e2
Tests for multiple events.
milkovsky 87dca7d
PR fixes.
milkovsky a58f03a
Inject the Rules event manager.
milkovsky cb7f762
Code formatting.
milkovsky 6fecbad
Merge branch '8.x-3.x' of github.com:fago/rules into feature/RUL-45
milkovsky 944aa09
After merge fix.
milkovsky 9ead81e
Initialize events [].
milkovsky 7332b45
Merge branch '8.x-3.x' into feature/2658842-event-handler-per-bundle
milkovsky 346ec1d
Merge branch 'feature/2658842-event-handler-per-bundle' into feature/…
milkovsky 92aacdc
Fix test after merge.
milkovsky b866850
Added ajax reload.
milkovsky 5b1a9c3
Bundle select + handler. WIP.
milkovsky c14b531
Merge branch '8.x-3.x' into feature/RUL-44
milkovsky df48c33
After merge fixes.
milkovsky 8e0c714
Merge branch '8.x-3.x' into feature/RUL-45
milkovsky 3378725
Merge branch 'feature/RUL-45' into feature/RUL-44
milkovsky 1b353fb
Fixed event discovery by base name.
milkovsky d179fcf
Fixed expression set in rules handler test.
milkovsky 0c297b6
Merge branch '8.x-3.x' into feature/RUL-45
milkovsky 5eea48c
Fix testMultipleEvents test.
milkovsky ab4e106
Merge branch 'feature/RUL-45' into feature/RUL-44
milkovsky c936dfc
Implemented summary().
milkovsky a341b28
Refactoring.
milkovsky fa7d831
Refactoring.
milkovsky f6266e3
Merge branch 'feature/RUL-44' of git://github.com/milkovsky/rules int…
fago 7fecba2
Worked over bundle configurable event.
fago File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,42 @@ | |
*/ | ||
class ConfigurableEventHandlerEntityBundle extends ConfigurableEventHandlerBase { | ||
|
||
/** | ||
* The bundles information for the entity. | ||
* | ||
* @var array | ||
*/ | ||
protected $bundlesInfo; | ||
|
||
/** | ||
* The entity info plugin definition. | ||
* | ||
* @var mixed | ||
*/ | ||
protected $entityInfo; | ||
|
||
/** | ||
* The entity type. | ||
* | ||
* @var string | ||
*/ | ||
protected $entityTypeId; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct(array $configuration, $plugin_id, $plugin_definition) { | ||
parent::__construct($configuration, $plugin_id, $plugin_definition); | ||
$this->entityTypeId = $plugin_definition['entity_type_id']; | ||
// @todo: This needs to use dependency injection. | ||
$this->entityInfo = \Drupal::entityTypeManager()->getDefinition($this->entityTypeId); | ||
// @tdo: use EntityTypeBundleInfo service. | ||
$this->bundlesInfo = \Drupal::entityManager()->getBundleInfo($this->entityTypeId); | ||
if (!$this->bundlesInfo) { | ||
throw new \InvalidArgumentException('Unsupported event name passed.'); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -30,42 +66,64 @@ public static function determineQualifiedEvents(Event $event, $event_name, array | |
* {@inheritdoc} | ||
*/ | ||
public function summary() { | ||
// Nothing to do by default. | ||
$bundle = $this->configuration['bundle']; | ||
$bundle_label = isset($this->bundlesInfo[$bundle]['label']) ? $this->bundlesInfo[$bundle]['label'] : $bundle; | ||
$suffix = isset($bundle) ? ' ' . t('of @bundle-key %name', array('@bundle-key' => $this->entityInfo->getBundleLabel(), '%name' => $bundle_label)) : ''; | ||
return $this->pluginDefinition['label']->render() . $suffix; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) { | ||
// Nothing to do by default. | ||
$form['bundle'] = array( | ||
'#type' => 'select', | ||
'#title' => t('Restrict by @bundle', array('@bundle' => $this->entityInfo->getBundleLabel())), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $this->t() |
||
'#description' => t('If you need to filter for multiple values, either add multiple events or use the "Entity is of bundle" condition instead.'), | ||
'#default_value' => $this->configuration['bundle'], | ||
'#empty_value' => '', | ||
); | ||
foreach ($this->bundlesInfo as $name => $bundle_info) { | ||
$form['bundle']['#options'][$name] = $bundle_info['label']; | ||
} | ||
return $form; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function extractConfigurationFormValues(array &$form, FormStateInterface $form_state) { | ||
$this->configuration['bundle'] = $form_state->getValue('bundle'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validate() { | ||
// Nothing to check by default. | ||
// Nothing to validate. | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getEventNameSuffix() { | ||
// Nothing to do by default. | ||
return isset($this->configuration['bundle']) ? $this->configuration['bundle'] : FALSE; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function refineContextDefinitions() { | ||
// Nothing to refine by default. | ||
if ($bundle = $this->getEventNameSuffix()) { | ||
$this->pluginDefinition['context']['entity']->setBundles([$bundle]); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function calculateDependencies() { | ||
// Nothing to calculate by default. | ||
// @todo: Implement. | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never split up translatable messages like this. Use 2 distinct t() calls instead.
Oh, and don't use t(), us $this->t() instead.