Skip to content

Commit

Permalink
WDC-16595 Updates based on code review;
Browse files Browse the repository at this point in the history
- Replaced dropbutton with operation elements
- Used new :placeholder for url placeholder values
- Move expressionManager to class property
  • Loading branch information
Daniel Sasser committed Oct 5, 2016
1 parent ef2f28c commit 26f2dcf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Form/Expression/ActionContainerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public function form(array $form, FormStateInterface $form_state) {
'#attributes' => ['class' => ['action-weight']],
];

// Operations (dropbutton) column.
// Operations column.
$rules_ui_handler = $this->getRulesUiHandler();
$row['operations'] = [
'data' => [
'#type' => 'dropbutton',
'#type' => 'operations',
'#links' => [
'edit' => [
'title' => $this->t('Edit'),
Expand Down
22 changes: 15 additions & 7 deletions src/Form/Expression/ConditionContainerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class ConditionContainerForm implements ExpressionFormInterface {
*/
protected $ruleExpression;

/**
* The expression plugin manager service.
*
* @var \Drupal\rules\Engine\ExpressionManager
*/
protected $expressionManager;


/**
* Creates a new object of this class.
*/
Expand All @@ -53,6 +61,7 @@ public function __construct(ConditionExpressionContainerInterface $condition_con
$this->rulesUiHandler = $this->getRulesUiHandler();
$this->component = $this->rulesUiHandler->getComponent();
$this->ruleExpression = $this->component->getExpression();
$this->expressionManager = \Drupal::service('plugin.manager.rules_expression');
}

/**
Expand All @@ -67,12 +76,12 @@ public function form(array $form, FormStateInterface $form_state, $options = [])
'#type' => 'container',
'#id' => 'rules-plugin-add-help',
'content' => array(
'#markup' => t('You are about to add a new @plugin to the @config-plugin %label. Use indentation to make conditions a part of this logic group. See <a href="@url">the online documentation</a> for more information on condition sets.',
'#markup' => t('You are about to add a new @plugin to the @config-plugin %label. Use indentation to make conditions a part of this logic group. See <a href=“:url">the online documentation</a> for more information on condition sets.',
array(
'@plugin' => $this->conditionContainer->getLabel(),
'@config-plugin' => $config->bundle(),
'%label' => $config->label(),
'@url' => 'http://drupal.org/node/1300034',
':url' => 'http://drupal.org/node/1300034',
)
),
),
Expand Down Expand Up @@ -177,11 +186,11 @@ private function buildRow(&$form, FormStateInterface &$form_state, $condition, $
'#attributes' => ['class' => ['condition-weight']],
];

// Operations (dropbutton) column.
// Operations column.
$rules_ui_handler = $this->getRulesUiHandler();
$row['operations'] = [
'data' => [
'#type' => 'dropbutton',
'#type' => 'operations',
'#links' => [
'edit' => [
'title' => $this->t('Edit'),
Expand Down Expand Up @@ -313,7 +322,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
* The id key in the values.
*
* @return mixed
* A heirarchical tree of values.
* A hierarchical tree of values.
*/
private function buildElementTree($values, &$elements, $pidKey, $idKey = NULL) {
$grouped = array();
Expand Down Expand Up @@ -352,13 +361,12 @@ private function buildElementTree($values, &$elements, $pidKey, $idKey = NULL) {
*/
private function mirrorElements($values) {
$elements = NULL;
$expressionManager = \Drupal::service('plugin.manager.rules_expression');
foreach ($values as $uuid => $element) {
$condition = $this->ruleExpression->getExpression($element['id']);
$configuration = $condition->getConfiguration();
unset($configuration['uuid']);
$configuration['weight'] = $element['weight'];
$elements[$uuid] = $expressionManager->createInstance($condition->getPluginId(), $configuration);
$elements[$uuid] = $this->expressionManager->createInstance($condition->getPluginId(), $configuration);
}

return $elements;
Expand Down

0 comments on commit 26f2dcf

Please sign in to comment.