Skip to content

Commit

Permalink
Merge pull request Sylius#7828 from foobarflies/form-type-doc
Browse files Browse the repository at this point in the history
[Documentation] Add missing 'form-type' attribute
  • Loading branch information
pjedrzejewski committed Mar 24, 2017
2 parents 3f1a6d9 + 21c7925 commit b1ff749
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
29 changes: 15 additions & 14 deletions docs/cookbook/custom-promotion-action.rst
Expand Up @@ -82,20 +82,6 @@ This class needs also a ``isConfigurationValid()`` method which was omitted in t
}
}
Register the action as a service
--------------------------------

In the ``app/config/services.yml`` configure:

.. code-block:: yaml
# app/config/services.yml
app.promotion_action.cheapest_product_discount:
class: AppBundle\Promotion\Action\CheapestProductDiscountPromotionActionCommand
arguments: ['@sylius.proportional_integer_distributor', '@sylius.promotion.units_promotion_adjustments_applicator']
tags:
- { name: sylius.promotion_action, type: cheapest_product_discount, label: Cheapest product discount }
Prepare a configuration form type for the admin panel
-----------------------------------------------------

Expand All @@ -120,6 +106,21 @@ The new action needs a form type to be available in the admin panel, while creat
}
}
Register the action as a service
--------------------------------

In the ``app/config/services.yml`` configure:

.. code-block:: yaml
# app/config/services.yml
app.promotion_action.cheapest_product_discount:
class: AppBundle\Promotion\Action\CheapestProductDiscountPromotionActionCommand
arguments: ['@sylius.proportional_integer_distributor', '@sylius.promotion.units_promotion_adjustments_applicator']
tags:
- { name: sylius.promotion_action, type: cheapest_product_discount, form-type: AppBundle\Form\Type\Action\CheapestProductDiscountConfigurationType, label: Cheapest product discount }
Register the form type as a service
-----------------------------------

Expand Down
22 changes: 12 additions & 10 deletions docs/cookbook/custom-promotion-rule.rst
Expand Up @@ -41,16 +41,6 @@ The new Rule needs a RuleChecker class:
}
}
Register the new rule checker as a service in the ``app/config/services.yml``:

.. code-block:: yaml
# apps/config/services.yml
app.promotion_rule_checker.premium_customer:
class: AppBundle\Promotion\Checker\Rule\PremiumCustomerRuleChecker
tags:
- { name: sylius.promotion_rule_checker, type: premium_customer, label: Premium customer }
Prepare a configuration form type for your new rule
---------------------------------------------------

Expand Down Expand Up @@ -87,6 +77,18 @@ And configure it in the ``app/config/services.yml``:
tags:
- { name: form.type }
Register the new rule checker as a service in the ``app/config/services.yml``:

.. code-block:: yaml
# apps/config/services.yml
app.promotion_rule_checker.premium_customer:
class: AppBundle\Promotion\Checker\Rule\PremiumCustomerRuleChecker
tags:
- { name: sylius.promotion_rule_checker, type: premium_customer, form-type: AppBundle\Form\Type\Rule\PremiumCustomerConfigurationType, label: Premium customer }
That's all. You will now be able to choose the new rule while creating a new promotion.

.. tip::
Expand Down
Expand Up @@ -35,7 +35,7 @@ public function process(ContainerBuilder $container)
$promotionActionTypeToLabelMap = [];
foreach ($container->findTaggedServiceIds('sylius.promotion_action') as $id => $attributes) {
if (!isset($attributes[0]['type'], $attributes[0]['label'], $attributes[0]['form-type'])) {
throw new \InvalidArgumentException('Tagged promotion action needs to have `type`, `form-type` and `label` attributes.');
throw new \InvalidArgumentException('Tagged promotion action `'.$id.'` needs to have `type`, `form-type` and `label` attributes.');
}

$promotionActionTypeToLabelMap[$attributes[0]['type']] = $attributes[0]['label'];
Expand Down
Expand Up @@ -35,7 +35,7 @@ public function process(ContainerBuilder $container)
$promotionRuleCheckerTypeToLabelMap = [];
foreach ($container->findTaggedServiceIds('sylius.promotion_rule_checker') as $id => $attributes) {
if (!isset($attributes[0]['type'], $attributes[0]['label'], $attributes[0]['form-type'])) {
throw new \InvalidArgumentException('Tagged rule checker needs to have `type`, `form-type` and `label` attributes.');
throw new \InvalidArgumentException('Tagged rule checker `'.$id.'` needs to have `type`, `form-type` and `label` attributes.');
}

$promotionRuleCheckerTypeToLabelMap[$attributes[0]['type']] = $attributes[0]['label'];
Expand Down

0 comments on commit b1ff749

Please sign in to comment.