Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

change block doc to best practices #794

Merged
merged 2 commits into from
Jan 23, 2017
Merged

change block doc to best practices #794

merged 2 commits into from
Jan 23, 2017

Conversation

dbu
Copy link
Member

@dbu dbu commented Jan 22, 2017

i will follow up with further PRs for the other sections, but first want feedback on this one.

fixes part of #591

@@ -56,7 +56,7 @@ for instance ``acme_main.block.rss``::

public function getType()
{
return 'acme_main.block.rss';
return 'block.rss';
Copy link
Member

Choose a reason for hiding this comment

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

It's often suggested to prefix with app. to avoid conflicts with a bundle called "block" for instance.

@@ -125,7 +125,7 @@ that knows how to fetch the feed data of an ``RssBlock``::
$resolver->setDefaults(array(
'url' => false,
'title' => 'Feed items',
'template' => 'AcmeMainBundle:Block:rss.html.twig',
'template' => 'AppBundle:Block:rss.html.twig',
Copy link
Member

Choose a reason for hiding this comment

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

app bundle templates should live in app/Resources/views/ and should be lowercased. So this would become block/rss.html.twig

sandbox_main.block.rss:
class: Acme\MainBundle\Block\RssBlockService
# app/config/services.yml
block.rss:
Copy link
Member

Choose a reason for hiding this comment

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

app. prefix here as well (and I suggest also showing the services: key in this example)

arguments:
- "acme_main.block.rss"
- "block.rss"
- "@templating"
tags:
- {name: "sonata.block"}
Copy link
Member

Choose a reason for hiding this comment

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

there should be spaces inside {} in Yaml

- "@templating"
tags:
- {name: "sonata.block"}

.. code-block:: xml

<service id="sandbox_main.block.rss" class="Acme\MainBundle\Block\RssBlockService">
<!-- app/config/services.xml -->
<service id="sandbox_main.block.rss" class="AppBundle\Block\RssBlockService">
Copy link
Member

Choose a reason for hiding this comment

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

sandbox_main -> app

Copy link
Member

Choose a reason for hiding this comment

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

And actually, it's recommended to make services short and with only one dot. So app.rss_block

Copy link
Member Author

Choose a reason for hiding this comment

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

i think this is a best practice i will ignore in my own projects. i find app.block.rss more logic. but for the cmf we should of course stick to those best practices as they are the compromise by the symfony community.

<argument type="service" id="templating" />
</service>

.. code-block:: php

// app/config/services.php

Copy link
Member

Choose a reason for hiding this comment

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

this empty line should be removed

<argument type="service" id="templating" />
</service>

.. code-block:: php

// app/config/services.php

use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

$container
->addDefinition('sandbox_main.block.rss', new Definition(
Copy link
Member

Choose a reason for hiding this comment

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

app.rss_block

@dbu
Copy link
Member Author

dbu commented Jan 23, 2017

thanks, updated

@dbu
Copy link
Member Author

dbu commented Jan 23, 2017

i actually did it inconsistently on purpose, to distinguish between the block type and the service name. (i find the sonata block thing quite confusing and very complicated. so maybe i just got wrong what the type is supposed to do). but if you think its better this way, i am fine with it.

@dbu dbu merged commit 84e6281 into 2.0 Jan 23, 2017
@dbu dbu deleted the best-practices branch January 23, 2017 09:35
@dbu dbu removed the wip/poc label Jan 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants