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

Domain structure content blocks #2096

Merged

Conversation

jeroendesloovere
Copy link
Member

Type

  • Enhancement

Resolves the following issues

New PR for #2091

Pull request description

The current ContentBlocks module in Fork CMS uses Doctrine and Symfony forms. That's amazing, but we are going a step further by dividing the logic in a folder called Domain. This is the way we are going to build all modules in Fork CMS. If you want to see some examples with the Domain folder, you can check out the MediaGalleries and MediaLibrary modules.

@jonasdekeukelaere
Copy link
Member

Isn't moving everything into a Domain folder (with only Command, Event and Exception in it's own folder) making it more complicated to see what is what? Instead of clear folder names Command, DBALType, Entity, Form, Repository?
And why the extra ContentBlocks folder in the Domain folder?
Also why make the action class name unnecessary longer?
Those changes seem a bit unclear to me really.

@carakas
Copy link
Member

carakas commented Jun 14, 2017

@jeroendesloovere I think in this case I would keep the action classes the same as they are in fork 4
With block you have post and category, it makes sense there, but here it just confuses. Also I'm not convinced by the examples you provide, there is no confusion possible here like it is with the blog

apart from that I agree with your points.

@carakas
Copy link
Member

carakas commented Jun 14, 2017

@jonasdekeukelaere It makes more sense to group all things related to the entity in one parent namespace and separate that from the structure of the cms

If you have a category and a post for instance just adding everything in repository is the wrong approach imho (and also others) since you are grouping it wrong, The repository of the category has nothing to do with the repository of the post.

The reason I am for this is because this is a way simpler module so it is easier to point to then a more complex module like the media library.

The structure should be consistent

@jonasdekeukelaere
Copy link
Member

For me it's more clearer to have (for example) all repositories, (or all Form types) in a folder together than have all those classes in 1 folder under Domain. Then you know directly what each class is suppose to do. But that sounds too easy maybe.

@carakas
Copy link
Member

carakas commented Jun 14, 2017

@jeroendesloovere I usually point to https://github.com/sumocoders/fork-partners/tree/master/src/Backend/Modules/Partners since it is a rather simple module. I also just used add edit delete there because it made sense

@carakas
Copy link
Member

carakas commented Jun 14, 2017

@jonasdekeukelaere no need to get passive aggressive

@jonasdekeukelaere
Copy link
Member

jonasdekeukelaere commented Jun 14, 2017

For example the partners module, you have everything in this 1 folder https://github.com/sumocoders/fork-partners/tree/master/src/Backend/Modules/Partners/Domain/Partner - doesn't look right, really.

To be honest, this change feels like a step backwards somehow.

@carakas
Copy link
Member

carakas commented Jun 14, 2017

the problem with your approach @jonasdekeukelaere is that the main goal of namespaces is to group and avoid naming collisions.

If you have a post and a category, and both of them have a status value object but it is not the same value object
Then in your case you would need to change the proper name of the class to keep your file stucture while you should do it with namespaces.

When there are a lot of things of the same type withing a domain namespace I always add an extra sublevel, for instance with commands

@jonasdekeukelaere
Copy link
Member

Then you can start making subfolders in your (for example) Repository or ValueObject folder.

@carakas
Copy link
Member

carakas commented Jun 14, 2017

removed since jeroens explanation was better

@jeroendesloovere
Copy link
Member Author

jeroendesloovere commented Jun 14, 2017

@jonasdekeukelaere
When I first started using doctrine and symfony, Entity/Type/ValueObject/DBALTYpe folders were the best things I've ever heard of...
Then @WouterSioen and @carakas told me about a Domain structure.
At first, I was against it, just like you.
But then I decided to try it once and damn now I've already created a shitload of new modules/apps using the Domain structure. It's so much more logical.

Take a look at this "Realizations module" example:
I swear, "I'm never going back to Entity/Form/..." structure.
schermafbeelding 2017-06-14 om 14 47 45

@jonasdekeukelaere
Copy link
Member

Ok agree about that the entity is the common thing. But then I would make subfolders in the Domain/ContentBlock folder. Because now in @jeroendesloovere his example you just have a bunch of files that not really belong together. Some are Entity, some are DTO, some Form type, some Repository.

Copy link
Member

@carakas carakas left a comment

Choose a reason for hiding this comment

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

@jonasdekeukelaere that is because you can't see beyond what they are to you, a form, a DTO etc but they belong together, just like 2 wheels, a frame, a steer and some other things form a bike and are useless apart from each other (to a certain level)


/**
* This is the add-action, it will display a form to create a new item
*/
class Add extends BackendBaseActionAdd
class ContentBlockAdd extends BackendBaseActionAdd
Copy link
Member

Choose a reason for hiding this comment

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

I would keep this as Add if for some unforeseeable reason this would once in the future make the naming incorrect we can tackle it then, for now I would keep it at Add, Edit, Delete, and Index

@@ -43,27 +38,55 @@ public function execute(): void
}

/** @var CreateContentBlock $createContentBlock */
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this anymore since the method has a return type and that gives us the autocompletion that this provided in the past

[
'report' => 'added',
'report' => 'content-block-added',
Copy link
Member

Choose a reason for hiding this comment

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

why did you change this?

$form = $this->createForm(
ContentBlockType::class,
new CreateContentBlock(),
['theme' => $this->get('fork.settings')->get('Core', 'theme', 'Core')]
Copy link
Member

Choose a reason for hiding this comment

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

see previous feedback, can you rebase on 5.0.0-dev because you are missing changes or fix this manually and check that you didn't occidentally remove something, I would personally prefer the rebase

/**
* This is the delete-action, it will delete an item.
*/
class ContentBlockDelete extends BackendBaseActionDelete
Copy link
Member

Choose a reason for hiding this comment

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

same comment as above

@jonasdekeukelaere
Copy link
Member

Sure they belong together, but for example all the code in 1 class belongs together as well, you will split that up into methods, right? For example the refactoring of all the installers. Why is that different with files and ok to just drop them al in 1 folder?

$this->redirect(
$this->getBackLink(
[
'report' => 'content-block-deleted',
Copy link
Member

Choose a reason for hiding this comment

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

idem

{
parent::execute();

/** @var ContentBlock $contentBlock */
Copy link
Member

Choose a reason for hiding this comment

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

idem

/**
* This is the edit-action, it will display a form to edit an existing item
*/
class ContentBlockEdit extends BackendBaseActionEdit
Copy link
Member

Choose a reason for hiding this comment

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

idem

return;
}

/** @var UpdateContentBlock $updateContentBlock */
Copy link
Member

Choose a reason for hiding this comment

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

idem

ContentBlockType::class,
new UpdateContentBlock($contentBlock),
[
'theme' => $this->get('fork.settings')->get('Core', 'theme', 'Core'),
Copy link
Member

Choose a reason for hiding this comment

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

idem

use Common\Locale;
use DateTime;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Table(name="content_blocks")
* @ORM\Entity(repositoryClass="Backend\Modules\ContentBlocks\Repository\ContentBlockRepository")
* @ORM\Entity(repositoryClass="Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlockRepository")
Copy link
Member

Choose a reason for hiding this comment

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

you should try it first, but I think because they are in the same namespace you can drop the FQCN and just use ContentBlockRepository

if ($dataTransferObject->hasExistingContentBlock()) {
$dataTransferObject->getContentBlockEntity()->status = Status::archived();

return self::create($dataTransferObject);
Copy link
Member

Choose a reason for hiding this comment

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

you repeat what is done below so you can just have the ifstatement and use one return here

@@ -1,68 +0,0 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

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

can you rebase and actually remove these files in the same commit as you create the new class so that git sees it as a move?

Copy link
Member

Choose a reason for hiding this comment

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

@jeroendesloovere this shows as outdated but I need you to look at it :p

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;

class ContentBlockStatusDBALType extends Type
Copy link
Member

Choose a reason for hiding this comment

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

idem

@@ -35,8 +35,8 @@ private function configureBackendNavigation(): void
$this->setNavigation(
$navigationModulesId,
$this->getModule(),
'content_blocks/index',
['content_blocks/add', 'content_blocks/edit']
'content_blocks/content_block_index',
Copy link
Member

Choose a reason for hiding this comment

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

I would revert this

Copy link
Member

@carakas carakas left a comment

Choose a reason for hiding this comment

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

See comments, something went wrong and the comments got posted as normal comments

@jeroendesloovere
Copy link
Member Author

@carakas thanks for your feedback. I've fixed it.

@jeroendesloovere
Copy link
Member Author

Except merging forkcms 5.0.0 dev

@jeroendesloovere
Copy link
Member Author

@carakas, can I rename the frontend action "Detail" to "ContentBlock"?

@carakas
Copy link
Member

carakas commented Jun 14, 2017

you can add a rename for the widget if you also provide the update query and info in the upgrade guide

@carakas carakas added this to the 5.0.0 milestone Jun 15, 2017
@carakas carakas merged commit 72ff9d9 into forkcms:5.0.0-dev Jun 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants