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.
This is for the Drupal 7 functional equivalent of https://www.drupal.org/node/2717641
Allow configuration of AMP metadata per content type.
Comment | File | Size | Author |
---|---|---|---|
#22 | interdiff-2734533-20-22.txt | 1.44 KB | RainbowArray |
#22 | 2734533-22-amp-metadata.patch | 18.72 KB | RainbowArray |
#15 | ampviewsource.png | 165.58 KB | RainbowArray |
#15 | ampbasic2.png | 86.93 KB | RainbowArray |
#15 | ampbasic.png | 110.02 KB | RainbowArray |
Comments
Comment #2
jazzdrive3 CreditAttribution: jazzdrive3 at Lullabot commentedHere is a patch of my work so far, utilizing ctools to define the fields for AMP metadata. The type can be selected on the Node Type form and overridden. More metadata types can be added easily through hook_amp_metadata_default(), and I imagine we'll want to support additional ones. Right now, the hook is the only way to define them, although adding a UI should be straightforward.
Organization name and logo are global settings.
It has full token support. For images, it asks for the URL, which can be gotten via tokens.
It also creates hook_amp_metadata_alter().
Overall, I think this is a good start and keeps things simple.
This does require the patch over at https://www.drupal.org/node/2734535 for the theme, as it was stripping out the script tag.
Comment #3
jazzdrive3 CreditAttribution: jazzdrive3 at Lullabot commentedComment #4
jazzdrive3 CreditAttribution: jazzdrive3 at Lullabot commentedUpdated patch with a fix for the default value of metadata type in the node type form.
Comment #5
RainbowArrayWith this patch, ctools becomes a dependency, so we should explicitly declare that dependency and perhaps provide a warning to somebody who upgrades with this patch so they know to install ctools. I got an ugly error message when I went to a content type page to edit the metadata there and didn't have ctools installed.
When I enabled ctools and went to the content type, when I go to the AMP Metadata vertical tab, I only see a select element for Type, and the options are empty.
That's a content type with AMP enabled, so it seems like something is going awry.
Comment #6
RainbowArrayReroll.
Comment #7
RainbowArrayTo get this working, I needed to install Token module as well as File Entity module and Image URL Formatter module to get an image URL from an image field token.
I also needed to apply the patch in #2734535: Stop removing AMP metadata JSON script element to the theme.
So, this does work. Now that #2717641: Add support for 'Top Stories with AMP' is in, I want to double-check to see if any of the fixes we made in that issue need to apply here.
This won't work the same in D7 and D8, and that's fine, but we should try to find areas of consistency. The D7 version asks for a date changed and date modified token while the D8 version generates that automatically. The D8 version provides image styles to help with the organization logo and content image formatting. Do we want to do that here? Provide fallback for processing an img element output by the content image token? Those are the sort of things I plan to look at next.
Comment #8
jazzdrive3 CreditAttribution: jazzdrive3 at Lullabot commentedRegarding dates, many sites don't use the default created and changed data from nodes to track and display that data. It's set by an editor somewhere else. That was the case with the site I was working on, where the published date was stored in another field.
Comment #9
RainbowArrayReviewed this, and I think there are few things from the D8 version that we'd want to get working with this as well.
Probably wouldn't hurt to port over some of the help text that we have in the D8 module as well.
Good point about the date created and modified fields. We may want to open an issue to add those fields for D8 if that's a common pattern.
Comment #10
RainbowArraySpoke with Matt Robison about this earlier today. I'll take care of getting a few fixes done before we get this in.
This patch takes care of removing the file entity dependent functions as well adding token as a dependency.
I'll be working on adding additional schema types and fallback image processing before this goes in.
I'll open up a follow-up issue for image styles, as that can be done separately.
I'll also probably look at help text and printing the JSON in the same way we do D8 (avoiding slash escapes and using pretty print).
Comment #11
RainbowArrayTook care of the remaining points from the review. Discussed this some more this afternoon with Matt R, and we decided we didn't need ctools exports, since each of the schema types have the same fields.
In a separate issue we can take care of image styles.
Comment #12
RainbowArrayOne last addition of a UI heading we had in the D8 version.
Comment #13
mtift@mdrummund: We probably should add warnings on admin/config/content/amp/metadata about requiring token and ctools (like we have with token in the D8 module).
Comment #14
mtiftUnfortunately, this is not working for me, and none of the metadata are appearing. Here's another thing to fix. I'll keep digging to try and figure out what's going on.
If there is no image, this will fail because getimagesize() requires a filename. Should check that $image_url exists before using it.
Comment #15
RainbowArrayFor what it's worth, this is what I'm seeing on my local:
Comment #16
RainbowArrayThis fixes the issues found in #13 and #14.
Also please note this requires running the dev version of amptheme, which prevents the json from being removed.
Comment #17
mtiftLooking better. Mostly nitpicks.
Is there a reason not to make this required? If so, we should leave off this line. Otherwise, I don't see the harm in making it required.
You could save a lot of code by putting the schema array in a separate helper function
It's nice that this appears on admin/reports/status, but I think it should appear on the metadata page, since it really only applies to existing AMP sites without ctools/token.
This is Drupal 7, so this should be the old array() syntax rather than the short array syntax.
Should not use short array syntax
Should not use short array syntax. I'll stop mentioning these and let you find the others. :)
This won't work. It needs to be something like
if (!empty($image_url))
spacing needs to be fixed
Missing period.
Comment #18
RainbowArrayRealized that amp_schema and amp_update_7101 were holdovers from when we were using ctools exportables, so removed those. All items should be fixed.
Comment #19
mtiftThis if statement will always be true, so you will never get into the else statement. Did you mean
if (!empty($enabled_types))
?If org logo is a required field, could it ever equal 0?
Since "Article image for carousel" isn't actually image field you will need to either validate that a token was added when that field is saved, or check that $image_url is actually a valid image before using it.
Comment #20
RainbowArrayMore fixes based on reviews. Thanks for the suggestions!
Comment #21
mtiftThe changes to the image logic make it so content type overrides to image metadata no longer appear. (I did not troubleshoot.)
Comment #22
RainbowArrayimage_get_info requires a stream-wrapped URI. This now converts an absolute URL to a stream-wrapped URI, so this is working again.
Comment #24
mtiftI'd say this is ready to go. Nice work, guys! Committed to 7.x-1.x.