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

[PagePartBundle] refactor PagePartReader and PageTemplateReader allowing using symfony configuration for storage #1109

Merged
merged 1 commit into from
May 4, 2016

Conversation

mlebkowski
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Fixed tickets -

The Goal

This is a general cleanup of the KunstmaanPagePartBundle with the main goal of extracting the PagePartConfigurationReader into a service implementing an interface (this way it could be easily extended or replaced).

There have been instances that I wanted to alter the way the pageTemplate is selected, etc. Having the class instance created in the methods body prevented me from extending it in any way.

New configuration method

The new feature is the ability to define pageparts and pagetemplates via the symfony configuration (the configuration values are exactly the same as in the yml files now), i.e.:

# app/config/config.yml
kunstmaan_page_part:
  pageparts: 
     article: … # same content as in `Resources/config/pageparts/article.yml`
   pagetemplates:
      homepage: 

This of course has the advantage of caching, validation, etc.

Breaking changes and stability

The breaking changes are described in the UPGRADE-X.X.md file. It’s hard to tell if they are even breaking, since they only touch on the internals, so I have mixed feelings about them. Anyway, they won’t affect users that didn’t tweak with the bundle mechanisms, i.e. a "StandardEdition" website will not break.

In the meantime I’m switching to this version in my new under-development website so I can spot any bugs that could be introduced, so this should be battle tested by the time 3.6 will be released. You don’t have a 3.6 branch yet, so I’m merging to master.

In closing

Do you have any feedback for me regarding this type of changes? I’d like to invest more time into cleanups like this — both keeping BC and breaking it for some future 4.0 release — but it would be a shame if they do not align with your roadmap.

@mlebkowski mlebkowski changed the title refactor PagePartReader and PageTemplateReader allowing using symfony configuration for storage [PagePartBundle] refactor PagePartReader and PageTemplateReader allowing using symfony configuration for storage Apr 12, 2016
@jockri
Copy link
Contributor

jockri commented Apr 14, 2016

Thanks for your contribution! We'll take a closer look to your refactoring later on. I'll keep you posted!

throw new \Exception(sprintf('Malformed namespaced configuration name "%s" (expecting "namespace:pagename").', $name));
}

list ($namespace, $name) = explode($name, ':', 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is making me crash whenever I try to visit any of the pages to edit them. For example on url /en/admin/nodes/2. However I see in the php documentation for the method explode that the delimeter should be the first argument and the string the second argument.

So I tried changing this line in explode(':', $name, 2); and now everything seems to work as expected again.

@mlebkowski
Copy link
Contributor Author

@Numkil, I included your suggestions in 0eb69d7.

Of course it was my error with the parameters order, good catch

$pagePartAdminConfigurators = $this->getPagePartAdminConfigurators($page);
foreach ($pagePartAdminConfigurators as $pagePartAdminConfigurator) {
$context = $pagePartAdminConfigurator->getContext();
if (!in_array($context, $result)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not relevant here but using in_array in a loop could potentially be extremely slow if the array starts growing a lot. In this case it's probably smarter to append $context to $result unconditionally and return array_keys(array_flip($result));

But as I said it's probably a non-issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

public function getPagePartContexts(HasPagePartsInterface $page) 
{
        $result = [];

        foreach ($this->getPagePartAdminConfigurators($page) as $configurator) {
            $result[$configurator->getContext()] = true;
        }

        return array_keys($result);
}

hm?

Copy link
Contributor

Choose a reason for hiding this comment

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

that's even better.

@Numkil
Copy link
Contributor

Numkil commented Apr 21, 2016

+1 Many useful improvements in the code. I wasn't able to find any other errors on the webpage so I assume it works quite well. @jockri

@mlebkowski
Copy link
Contributor Author

Guys, honestly, that is the response I was anticipating. I offered an in-depth involvement and quality contributions, but you don’t seem to be interested. In the meantime you didn’t hesitate to merge a conflicting PR, giving me additional work if I wanted to get this merged in…

@jockri
Copy link
Contributor

jockri commented May 2, 2016

Hi @mlebkowski , sure we are interested and thankful for your great contributions, let that be clear!
There is indeed a small PR merged that added an extra feature/option...
Can you rebase so we can merge before there are more conflicts?
Thanks!

@jockri jockri merged commit 62dc60f into Kunstmaan:master May 4, 2016
@jockri jockri added this to the 3.5.2 milestone May 4, 2016
@jockri
Copy link
Contributor

jockri commented May 4, 2016

Thanks!

jockri pushed a commit that referenced this pull request May 19, 2016
* master:
  Translate adminlist excel export headers
  [AdminBundle]: remove check for user token
  [NodeBundle] unpublish needs to be publish (#1157)
  Hungarian translations - from István Molitor
  refactor `PagePartReader` and `PageTemplateReader` allowing using symfony configuration for storage (#1109)
@mlebkowski mlebkowski deleted the feature/refactor-pageparts branch July 7, 2016 07:52
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