Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I built a sandbox module creating a yoast_seo report utilizing a node preview. It simply creates a report by passing the rendered content to the yoast_seo library, there is no instant feedback on the form like in this modules implementation, instead the report is triggered by using a seo preview button. The major advantage of using the preview is, that you can easily include all different field types like paragraphs, nested fields, also it takes view mode settings into account.
If you are interested maybe we could find a way to combine the functionalities.
Comment | File | Size | Author |
---|---|---|---|
#13 | interdiff-11-13.txt | 616 bytes | Kingdutch |
#13 | yoast_seo-node-preview-sandbox-2917280-13.patch | 24.9 KB | Kingdutch |
| |||
#11 | interdiff-9-11.txt | 4.41 KB | Kingdutch |
Comments
Comment #2
KingdutchHi volkerk!
Cool! Thanks for the suggestion.
If you look at the latest development version of the 2.x version then you can actually see that I've implemented something similar by rendering the entity. This has the added benefit that it's not coupled to nodes which means the module can also be used with other entity types.
When I have some time, I'll check out your solution to see if we can improve what's in the module!
For now, some more work will be required before we can do a 2.0 alpha but if you could test what's in the 2.x development branch then that would be appreciated greatly!
~ Alexander
Comment #3
KingdutchHi volkerk,
I took a look at your module and it's an interesting approach. My main gripe with it is that it doesn't work for entities other than nodes and that it won't work nicely together with other modules that try to take over the Node preview form handler.
There is definitely some things that can be learned from your Sandbox and used in the module though. For example we don't have a hook_help implementation in the RTSEO module yet and I think your metatags retrieval for some items (title, meta description) is a bit more elegant than the the current implementation. I also think that any alter hooks for metatags might currently not work for the previews of the Real-Time SEO module.
I'll leave this issue open but we should see if we can incorporate the above things in separate issues and close this meta-issue.
I look forward to hearing your thoughts. It would be cool if the 2.x version of this module could be used in Thunder.
~ Alexander
Comment #4
KingdutchComment #5
volkerk CreditAttribution: volkerk at Thunder commentedHi Kingdutch,
thank you for your feedback, I updated the sandbox module, it now works for all entities which implement the EditorialContentEntityType class, this covers node, taxonomy_term and media entities and should be future proof.
I had a look at the 8.x-2.x branch of the yoast_seo module, I see that you provide a preview functionality as well now, unfortunately it does not play well with the thunder distribution: #2927081: Preview does not work for paragraphs
Also I am not sure about doing the request handling and building the form_state yourself, may I suggest that we join our efforts, I would very much like to provide you a patch which incorporates the approach I used in the sandbox module into the ajax preview handling of the yoast_seo module.
Comment #6
KingdutchHi Volkerk,
The preview not working for paragraphs is something I encountered as well. It seemed to work with the most basic paragraph but doesn't like some of the fields (my simplest case seems to be a paragraph with a dropdown).
My next step is to write a failing test in #2573899: Paragraphs module support and see if I can fix that.
Personally I think the way the AJAX request is handled is quite elegant. I think it can cover most any entity type (if we get the field value extraction fixed). I would at least like to make sure that the entity generation from form values and the move from entity to values that are usable by the JavaScript library are kept separate.
How would you suggest we approach it?
Comment #7
volkerk CreditAttribution: volkerk at Thunder commentedHi kingdutch,
you are right, we should definitely keep the EntityPreviewer service.
The problem with the recreation of $form and $form_state is, that some Widgets rely on the original form object to handle data.
What about this: we go with the form handler class to get a proper submit on the form object, but keep the previewer service for preparing the data for the JavaScript library?
Comment #8
KingdutchWriting down a realisation I just had.
I believe the bug in the current implementation in the module is that validation logic is required to massage the values properly. Validation logic's execution depends on the button that created the form validation request. The current javascript logic that uses a separate route doesn't have a proper method to select the submit button as the triggering element. Once a paragraph element is added then the default selected button becomes one of paragraphs which causes some of the validation logic to malfunction. Adding a separate form handler with a corresponding button that can be used to trigger submission circumvents this.
I'm warming up to this approach more and more as it requires less reconstruction of Drupal core methods and solves the above problem more elegantly.
I'll see if I can extract the relevant parts from your sandbox today or tomorrow :)
Comment #9
KingdutchI a little while later, I've come to the attached patch that I gave the following commit message:
You can also see this on the feature/improved-preview branch that I pushed. I had begun writing a test but I forgot to push that work from my work laptop so the attached patch only implements the functionality using your sandbox as guide.
Please let me know what you think and if this works for you :)
Comment #11
KingdutchThe configuration page test caught an error where there was still a reference to the route that was made obsolete. Attached is the fix for this. It also fixes the coding standards that were reported. There's also a slight change in the test to use absolute URLs but that shouldn't functionally change anything.
Comment #13
KingdutchWhelp, that's embarrassing.
Comment #14
volkerk CreditAttribution: volkerk at Thunder commentedGreat work!
I have tested this in thunder and default drupal with paragraphs installed. Preview functionality works fine.
I had two nitpicks but I think we can address them later:
* #2935670: RTSEO.js library is too verbose.
* #2935681: Handlers are not attached
Anyway, I think this is a big improvement, thank you very much.
Comment #16
KingdutchI'm marking this issue as fixed. The latest dev commit of 2.x includes support for analysing nodes with Paragraphs. I've created a follow up for this issue to write tests but that's blocked by work in the paragraphs module: #2937665: Write a test for Paragraphs module support
Thanks for the help!
Comment #18
ras-ben CreditAttribution: ras-ben commentedHey Kingdutch
I'm not sure if I'm doing something wrong, but I really cant this to work
I'm using the latest (2.0.0-alpha3) and when i preview a node, i dont see any SEO report anywhere..
I've looked through settings everywhere, both on the CT and the module and I cant seem to find anything relevant :(
How is this supposed to work? Am I meant to see the report when i go to a preview URL, e.g. https://site.dev/node/preview/3e12460c-72a4-470b-a2fa-b8eeffa10d39/full ?
Thanks in advance :)