Skip to content
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

Plugin development guide v1.0 #9592

Merged
merged 10 commits into from Jul 26, 2018
Merged

Conversation

Zales0123
Copy link
Member

@Zales0123 Zales0123 commented Jul 17, 2018

This is the first version of a new Plugin Development Guide - providing the simplest, fastest and the most explained way to create a new Sylius Plugin. I would like to see your opinion, what is missing, what is incomplete, what is not necessary. The implementation works, I've been checking it during writing the guide 😄

@Zales0123 Zales0123 changed the title Plugin development guide v. 1.0 Plugin development guide v1.0 Jul 17, 2018
@Zales0123 Zales0123 added the Documentation Documentation related issues and PRs - requests, fixes, proposals. label Jul 17, 2018
@Zales0123 Zales0123 changed the base branch from master to 1.1 July 17, 2018 09:07
@pjedrzejewski
Copy link
Member

I'd replace the entire "Plugins" part of docs with "Plugin Development Guide" and make it a first-level element, like the book. The "Creating plugin" doc could be first or second step of the guide.


.. important::

Of course you need to remember about entity mapping customization as well.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add example here, it will be really simple but important and easy to miss if you are new to Sylius.

classes:
model: IronMan\SyliusProductOnDemandPlugin\Entity\ProductVariant

This configuration should be placed in ``src/Resources/config/config.yml``. It also has to be imported

This comment was marked as resolved.

This comment was marked as resolved.

}
}

Translation keys placed in ``src/Resources/translations/message.{locale}.yml`` will be resolved automatically.

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example or link to example?


.. code-block:: yaml

services:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these services should be inside of the plugin not the test app. Because you want to load them automatically and not define for each app manually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally agreed, I was thinking about src/Resources/config/services.yml, it's a typo 😄

* by writing a theme

For the needs of this tutorial, we would go the first way. What's crucial, we need to determine which template should be overwritten.
Naming for twig files in Sylius, both in **Shop** and **AdminBundle** are pretty clear and straightforward. In this specific case,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistency, one has a suffix (Bundle) and the other does not.


* ``src/Controller/GreetingController.php``

* ``src/Resources/config/admin_routing.yml``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend src/Resources/config/routing/admin.yml.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it needs to be changed in PluginSkeleton, as it's about removing this file :)

.. image:: ../../_images/product_variant_available_on_demand.png
:align: center

What's next?

This comment was marked as resolved.

--------------

The goal of our plugin is simple - we need to extend ``ProductVariant`` entity and provide new flag, that could be set
on product variant form. Following customizations uses information provided in **Sylius Customization Guide**, especially
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following customization uses... or Following customizations use...


then don't be afraid to make a regular Sylius customization.

For needs of this tutorial, we would implement a simple plugin, making possible to mark product variant **available on demand**.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will implement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And could we make an info box out of this information?

Model
*****

The only field we need to add is additional ``$availableOnDemand`` boolean. Of course we should start with the unit tests (written with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an additional


.. code-block:: yaml

sylius_product:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other dosc we are using a comment indicting in which file are we adding stuff, wdyt about doing it everywhere in this tutorial also?

.. warning::

Remember that if you modify or add some mapping, you should either provide a migration for the plugin user (that could be
copied to their migration folder) or mention in installation process requirement of migration generation!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mention the requirement of migration generation in the installation process!

.. note::

Remember about naming convention! Sylius plugin should start with your vendor name, followed by ``Sylius`` prefix and with ``Plugin`` suffix at the end.
Let's say your vendor name is **IronMan**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing dot ;)

I'd add sth like
Come on **IronMan**, let's create your plugin! 🎉


You **don't** have to remove all these files mentioned above. They can be adapted to suit your plugin functionality. However, as
they provide a default, dummy features only for the presentation reasons, it's just easier to delete them and implement new ones by
your own.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by on your own

Then I should be notified that it has been successfully edited
And this variant should be available on demand

What is really important, usually you don't need to write the whole Behat scenario on your own! In the example above only 2 steps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to write the whole Behat scenario on your own! - well actually, you do. You just don;t need to implement all these steps you've written :D

.. important::

If you're not familiar with our BDD workflow, with Behat, take a look at
:doc:`our BDD guide</bdd/index>`. All Behat configuration (contexts, pages, services, suites etc.) are explained
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configuration -> configurations
or All -> Whole

}
}

First step is done - we have a failing test, that would be green when we implement a desired functionality.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is going to go green ?

@@ -0,0 +1,59 @@
Naming changes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a general thought: it would be great to have some way to achieve it automatically (e.g. only pass your vendor plus plugin name and it would rename all the things and delete exemplary stuff).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agreed 👍 However right now it has to be done manually, so I'm documenting it anyway

@pamil pamil self-requested a review July 17, 2018 15:46
@Zales0123
Copy link
Member Author

@pjedrzejewski I agree that the "plugins" section can be a little bit restructured. I would personally leave the separate "creating plugin" chapter, as it only explains a few simple steps how to start with plugin development, not involving the whole big tutorial. However, I would leave it as it is for now, as this PR already provides plenty of lines to review - we could make these rearrangements a little bit later in one, simple, tiny PR :)

@dukusz
Copy link
Contributor

dukusz commented Jul 19, 2018

Dear @Zales0123! I'm really impressed with your work. Just found a sec to read it and it's so clear and simple that I'm keen on creating a plugin, even though I've never written a single line of code. Keep on rocking! 💃 #goodvibes

Summary
-------

Congratulations! You've created your first, fully tested and documented, customization to Sylius inside a Sylius plugin!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! 🥇

Naming changes
--------------

``PluginSkeleton`` provides some default classes and configurations. However, they must have some default values and names that should be changed,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the whole text is very well-written, I'm pretty sure that a comma after changed is unnecessary :D

-------

Congratulations! You've created your first, fully tested and documented, customization to Sylius inside a Sylius plugin!
As you can see, there are some things to do at the beginning of development, but know, when you are already familiar with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but now


Congratulations! You've created your first, fully tested and documented, customization to Sylius inside a Sylius plugin!
As you can see, there are some things to do at the beginning of development, but know, when you are already familiar with
the whole structure, each next feature can be provided faster than the previous one.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be delivered faster than the previous ones ?

customizing the whole :doc:`order processing</components_and_bundles/bundles/SyliusOrderBundle/processors>` and :doc:`inventory operations</components_and_bundles/bundles/SyliusInventoryBundle/services>`

and even more. The limit is only your imagination (and business value, of course!), for more inspiration, we strongly recommend
our :doc:`customizing guide</customization/index>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The limit is only your imagination (and business value, of course!). For more inspiration, we strongly recommend...

?


.. important::

If you're not familiar with our BDD workflow, with Behat, take a look at
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're not familiar with our BDD workflow with Behat, [...]

Unnecessary comma

@bartoszpietrzak1994
Copy link
Contributor

bartoszpietrzak1994 commented Jul 20, 2018

Now that's a piece of outstanding work! 🥇

--------------

The goal of our plugin is simple - we need to extend ``ProductVariant`` entity and provide new flag, that could be set
on product variant form. Following customizations use information provided in **Sylius Customization Guide**, especially
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following customizations are done just like in the **Sylius Customization Guide**, take a look at :doc:`customizing models</customization/model>`, :doc:`form</customization/form>` and :doc:`template</customization/template>`.


``PluginSkeleton`` is focused on delivering the most friendly and testable environment. That's why in ``tests/Application`` directory,
there is a **tiny Sylius application** placed, with your plugin already used. Thanks to that, you can test your plugin with Behat scenarios
**within** Sylius application without installing it to any test app manually! There is, however, one important consequence of such an architecture.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why bold on within? and Everything below? :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To note about an awesome feature (you can test plugin in the application without installing it into the application 🎉) and make reader 100% aware about the need of copying everything that is needed to the test application :)

type: boolean
nullable: true

Then our new entity should be configured as sylius product variant resource model:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then our new entity should be configured as a resource model:

.. warning::

Remember that if you modify or add some mapping, you should either provide a migration for the plugin user (that could be
copied to their migration folder) or mention the requirement of migration generation in the installation process!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

installation process -> installation instructions?


* ``Tests\\Acme\\SyliusExamplePlugin\\`` -> ``Tests\\IronMan\\SyliusProductOnDemandPlugin\\`` (the same changes should be done in namespaces in ``tests/`` directory

* ``AcmeSyliusExamplePlugin`` should be renamed to ``IronManSyliusProductOnDemandPlugin``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why some of these points are tabbed and some are not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of them are sub-points for other points (e.g. "In composer.json" have few of them, as there are few things that need to be changed in composer.json file)


That's it! All other files are just a boilerplate to show you what can be done in the Sylius plugin. They can be deleted with no harm.

* All files from ``features/`` directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why * here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To point out every file that should be removed


.. important::

You **don't** have to remove all these files mentioned above. They can be adapted to suit your plugin functionality. However, as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**don't have to**

.. important::

You **don't** have to remove all these files mentioned above. They can be adapted to suit your plugin functionality. However, as
they provide a default, dummy features only for the presentation reasons, it's just easier to delete them and implement new ones on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide a default

And this variant should be available on demand

What is really important, usually you don't need to implement the whole Behat scenario on your own! In the example above only 2 steps
would need a custom implementation. Rest of them can be easily reused from **Sylius** Behat system.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behat system? or rather Behat suite?

As a result, you should see a new field in product variant form:

.. image:: ../../_images/product_variant_available_on_demand.png
:align: center

This comment was marked as resolved.


.. tip::

For needs of this tutorial, we will implement a simple plugin, making possible to mark product variant **available on demand**.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the purpose of this tutorial, we will implement a simple plugin: making it possible to mark a product variant **available on demand**.

Implementation
--------------

The goal of our plugin is simple - we need to extend ``ProductVariant`` entity and provide new flag, that could be set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to extend the ProductVariant entity

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and provide a new flag
that could be set on the product variant form

Model
*****

The only field we need to add is an additional ``$availableOnDemand`` boolean. Of course we should start with the unit tests (written with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's good to use of course in tutorials - same as words like simply, just do, just add, etc. These actions are not familiar to everyone yet and might require a link or additional explanation.

@stefandoorn
Copy link
Contributor

Nice guide! :-)

*****

The only field we need to add is an additional ``$availableOnDemand`` boolean. We should start with the unit tests (written with
PHPSpec/PHPUnit/any other unit testing tool):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"PHPSpec, PHPUnit or any other...?" would prevent us from having onelongwordwithoutspaces. :)


use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant;

class ProductVariant extends BaseProductVariant implements ProductVariantInterface

This comment was marked as resolved.

class ProductVariant extends BaseProductVariant implements ProductVariantInterface
{
/** @var bool */
private $availableOnDemand;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about providing a default value for this property and removing nullable typehints? I think it makes sense for a boolean.


* ``Acme\SyliusExamplePlugin`` -> ``IronMan\SyliusProductOnDemandPlugin``

That's it! All other files are just a boilerplate to show you what can be done in the Sylius plugin. They can be deleted with no harm.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"They can be deleted with no harm." -> "They can be deleted with no harm:" in order to indicate, that the list below is directly connected with this sentence?

and even more. The limit is only your imagination (and business value, of course!). For more inspiration, we strongly recommend
our :doc:`customizing guide</customization/index>`.

At the end, do not hesitate to contact us on contact@sylius.com when you manage to implement a new plugin. We would be happy to check it out
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contact us at

our :doc:`customizing guide</customization/index>`.

At the end, do not hesitate to contact us on contact@sylius.com when you manage to implement a new plugin. We would be happy to check it out
and add it to our `official plugins list`_!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention, that the plugin needs to be high-quality (with tests etc.) in order to be in our official plugins list.

@pamil pamil merged commit e8ea71d into Sylius:1.1 Jul 26, 2018
@pamil
Copy link
Contributor

pamil commented Jul 26, 2018

Thank you, Mateusz! 🎉

@Zales0123 Zales0123 deleted the plugin-development-guide branch July 26, 2018 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Documentation related issues and PRs - requests, fixes, proposals.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants