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

Feature: Support partial rendering #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

alexander-nitsche
Copy link

@alexander-nitsche alexander-nitsche commented Mar 7, 2023

Hi Dmitri,

@dlubitz and I recently wanted to use this package to render partials consisting of a Fusion object and a content node via AJAX. We didn't want to use the built-in Psmb.Ajaxify:Ajaxify, but instead retrieve the partial key and use that in our own AJAX implementation. Therefore, we added some features to this package to make it work, mainly:

  1. Support partial rendering of any content node by caching the content node along with the Fusion path.
  2. Support for using Psmb.Ajaxify:RenderPath standalone to retrieve the partial key.
  3. Replacing manual assignment of a unique partial key via the property name with automatic generation of the partial key as a hash of the content node identifier and the Fusion path,

and I made some final revisions and reformatting of the code to reflect and unify the new naming conventions and common Neos CMS code styles. I've broken these changes into their own commits for ease of review.

I marked two commits as breaking change because they changed some API names, even though the main Psmb.Ajaxify:Ajaxify access point remains unchanged. I think it would be useful to reflect these breaking changes in an increase to the major release version to inform users of the new naming conventions.

I followed the naming conventions of the Neos core packages as much as possible and tried to be backwards compatible with Neos 3.0 by comparing the code statements used with those of Neos Core 3.0. Finally, I tested the changes in a local Neos 7.3 instance, where they worked as expected.

No features were removed, only added.

Thank you very much for your work and greetings!
Alex

With this patch, in addition to document nodes, you can also have
content nodes (partials) re-rendered via AJAX requests. The identifier
of the node is now stored in the cache entry along with the Fusion
path and is thus available on request to render the partial.
A key feature of this package is to associate a partial with a unique
partial key for later dedicated rendering in AJAX requests. The
implementation strictly relied on a defined position of the responsible
Psmb.Ajaxify:RenderPath within the Psmb.Ajaxify:Ajaxify Fusion
object. With this patch, that relationship has been relaxed: the
Psmb.Ajaxify:RenderPath Fusion object can now be used both standalone
and nested within any depth of Psmb.Ajaxify:Ajaxify. However, when
used standalone, it must be called at the first level of the partial -
in the same way as Psmb.Ajaxify:Ajaxify.
Psmb.Ajaxify:Ajaxify and Psmb.Ajaxify:RenderPath can be assigned to
the same generic property name in all occurrences for better code
readability.
The partial key must be unique per Fusion path and content node.
Therefore, the current state of one key per Fusion path is not
sufficient. With this patch, the key will be a hash based on both
attributes.

The hash is generated automatically, thereby removing the requirement
for the developer to manually specify a unique key.

Because this patch changes the value of the publicly used URL parameter
`&ajaxPathKey=<value>` this patch is marked as breaking.
Previously, partial rendering considered only the Fusion path. With the
recent changes, both the Fusion path and the content node, called the
partial context, are now considered. Consider this change in the naming
conventions. In detail these are:

- Public: Rename URL parameter "ajaxPathKey" to "ajaxPartialKey".
- Public: Rename `Psmb.Ajaxify:RenderPath` to `Psmb.Ajaxify:PartialSerializer`.
- Public: Rename `Psmb.Ajaxify:RenderPathResolver` to `Psmb.Ajaxify:PartialResolver`.
- Public: Rename "[P]athsCache" to "[Pp]artialCache" cache identifier.
- Private: Use FQDN for \Exception to satisfy the editor :).
- Private: Use verbose common "fusionPath" over "path" and "renderPath".
- Private: Rename "pathKey" to "partialKey".
- Private: Even smaller adjustments ..

Since this patch changes the naming of some public elements, it is marked
as breaking. And breaking changes are included because there were other
breaking changes in this patch already.
Apply PSR-2 and general Neos .editorconfig styles to the codebase to
eliminate mixing of styles and facilitate future patching.
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.

1 participant