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.
Convert _amp_get_amp_url(), _amp_build_metadata(), _amp_get_merged_metadata(), and _amp_prepare_metadata_json() in amp.module into services.
amp_build_metadata() can probably be a render element, since it is outputting a render array. Generic service classes for _amp_get_merged_metadata and _amp_prepare_metadata_json.
Doing this will make this code more extensible and testable.
Comment | File | Size | Author |
---|---|---|---|
#7 | interdiff-5-7.txt | 3.05 KB | RainbowArray |
#7 | 2745221-7-refactor-amp-metadata.patch | 36.7 KB | RainbowArray |
Comments
Comment #2
RainbowArrayComment #3
RainbowArrayRefactored the first chunk of the amp.module code. This takes care of the refactoring of the JSON metadata preparation. Tried to construct this in a way so that in theory if somebody wanted to extend this to add additional metadata JSON, it should be possible to do so.
More refactoring necessary, but this was one of the biggest chunks.
Comment #4
RainbowArrayThis refactors the remainder of the helper functions in amp.module.
Comment #5
RainbowArrayThis adds an interface for AmpPrepareMetadataJson. That seems like the class that would most likely be reused to do some different things with the metadata.
With that, I think this is ready for review.
Comment #6
mtiftLooking good. Working well. Here's some initial feedback:
Just "@var array" should be enough
Just "@var array" should be enough
Just "@var array" should be enough (and $ampTypeMetadata seems incorrect)
I think you mean @var \Drupal\Core\Entity\EntityTypeManagerInterface
I think this should be
use Drupal\Core\Entity\EntityTypeManagerInterface;
This should be $EntityTypeManagerInterface
This does not look right. You should check before you assign the variables to properties, not after. Another way to do this would be to assign default values for method parameters.
And something in this patch is causing this error, but I'm not sure what:
Comment #7
RainbowArrayThis should address the feedback from points 1-7 in #6. I didn't encounter the htmlspecialchars() error. Hopefully the proper checking of the variables in #7 is preventing that? If that error still comes up, maybe a screenshot would help? That line that is referenced is as follows if that's helpful:
Thanks so much for the feedback mtift!
Comment #8
RainbowArrayComment #10
mtiftNice work, @mdrummund. Committed to 8.x-1.x.
Comment #12
mtift