diff --git a/schema_special_announcement/config/schema/schema_announcement.metatag_tag.schema.yml b/schema_special_announcement/config/schema/schema_announcement.metatag_tag.schema.yml new file mode 100644 index 0000000..6059f44 --- /dev/null +++ b/schema_special_announcement/config/schema/schema_announcement.metatag_tag.schema.yml @@ -0,0 +1,45 @@ +# The 'type' should be "label" for short meta tags and "text" for ones which +# could get longer, especially ones which use a textarea field instead of a +# textfield. +metatag.metatag_tag.schema_special_announcement_category: + type: text + label: 'Category' +metatag.metatag_tag.schema_special_announcement_date_posted: + type: text + label: 'Date Posted' +metatag.metatag_tag.schema_special_announcement_disease_prevention_info: + type: text + label: 'Disease Prevention Info' +metatag.metatag_tag.schema_special_announcement_disease_spread_statistics: + type: text + label: 'Disease Spread Statistics' +metatag.metatag_tag.schema_special_announcement_expires: + type: text + label: 'Expires' +metatag.metatag_tag.schema_special_announcement_getting_tested_info: + type: text + label: 'Getting Tested Info' +metatag.metatag_tag.schema_special_announcement_name: + type: text + label: 'Name' +metatag.metatag_tag.schema_special_announcement_news_updates_and_guidelines: + type: text + label: 'News Updates and Guidelines' +metatag.metatag_tag.schema_special_announcement_public_transport_closures_info: + type: text + label: 'Public Transport Closures Info' +metatag.metatag_tag.schema_special_announcement_school_closures_info: + type: text + label: 'School Closures Info' +metatag.metatag_tag.schema_special_announcement_text: + type: text + label: 'Text' +metatag.metatag_tag.schema_special_announcement_travel_bans: + type: text + label: 'Travel Bans' +metatag.metatag_tag.schema_special_announcement_type: + type: label + label: '@type' +metatag.metatag_tag.schema_special_announcement_url: + type: text + label: 'Url' diff --git a/schema_special_announcement/schema_special_announcement.info.yml b/schema_special_announcement/schema_special_announcement.info.yml new file mode 100644 index 0000000..435b393 --- /dev/null +++ b/schema_special_announcement/schema_special_announcement.info.yml @@ -0,0 +1,8 @@ +name: Schema.org SpecialAnnouncement +type: module +description: Adds Schema.org/SpecialAnnouncement to the JSON LD array. Creates SpecialAnnouncement. +core: 8.x +core_version_requirement: ^8 || ^9 +package: SEO +dependencies: + - schema_metatag:schema_metatag diff --git a/schema_special_announcement/src/Plugin/metatag/Group/SchemaSpecialAnnouncement.php b/schema_special_announcement/src/Plugin/metatag/Group/SchemaSpecialAnnouncement.php new file mode 100644 index 0000000..c680044 --- /dev/null +++ b/schema_special_announcement/src/Plugin/metatag/Group/SchemaSpecialAnnouncement.php @@ -0,0 +1,19 @@ +:url.", arguments = { ":url" = "https://schema.org/SpecialAnnouncement"}), + * weight = 10, + * ) + */ +class SchemaSpecialAnnouncement extends SchemaGroupBase { + // Nothing here yet. Just a placeholder class for a plugin. +} diff --git a/schema_special_announcement/src/Plugin/metatag/Tag/SchemaSpecialAnnouncementCategory.php b/schema_special_announcement/src/Plugin/metatag/Tag/SchemaSpecialAnnouncementCategory.php new file mode 100644 index 0000000..924125a --- /dev/null +++ b/schema_special_announcement/src/Plugin/metatag/Tag/SchemaSpecialAnnouncementCategory.php @@ -0,0 +1,28 @@ + 'SchemaSpecialAnnouncementReviewRating', + 'schema_special_announcement_review_body' => 'SchemaSpecialAnnouncementReviewBody', + 'schema_special_announcement_date_published' => 'SchemaSpecialAnnouncementDatePublished', + 'schema_special_announcement_item_reviewed' => 'SchemaSpecialAnnouncementItemReviewed', + 'schema_special_announcement_name' => 'SchemaSpecialAnnouncementName', + 'schema_special_announcement_author' => 'SchemaSpecialAnnouncementAuthor', + 'schema_special_announcement_type' => 'SchemaSpecialAnnouncementType', + ]; + +} diff --git a/src/Plugin/metatag/Tag/SchemaCreativeWorkTrait.php b/src/Plugin/metatag/Tag/SchemaCreativeWorkTrait.php index cd81850..785f550 100644 --- a/src/Plugin/metatag/Tag/SchemaCreativeWorkTrait.php +++ b/src/Plugin/metatag/Tag/SchemaCreativeWorkTrait.php @@ -183,7 +183,9 @@ trait SchemaCreativeWorkTrait { 'CreativeWorkSeries', 'TVSeries', 'Episode', + 'WebContent', 'WebPage', + 'WebPageElement', 'WebSite', ]; } diff --git a/src/Plugin/metatag/Tag/SchemaUrlWebContentBase.php b/src/Plugin/metatag/Tag/SchemaUrlWebContentBase.php new file mode 100644 index 0000000..d140318 --- /dev/null +++ b/src/Plugin/metatag/Tag/SchemaUrlWebContentBase.php @@ -0,0 +1,90 @@ +value()); + + // If this is a complex array of value, process the array. + if (is_array($value)) { + + // Clean out empty values. + $value = SchemaMetatagManager::arrayTrim($value); + } + + if (empty($value)) { + return ''; + } + + // If url return simple value, else return WebContent. + if ($value['@type'] === 'Url') { + return $this->processItem($value['url']); + } + + return parent::output(); + } + + /** + * {@inheritdoc} + */ + public function form(array $element = []) { + $form = parent::form($element); + + $state = [':input[name="' . $this->visibilitySelector() . '[@type]"]' => ['value' => 'Url']]; + $form['@type']['#options']['Url'] = $this->t('Url'); + foreach (SchemaWebContentTrait::creativeWorkProperties('All') as $name => $property) { + if ($name === 'url') { + continue; + } + $form[$name]['#states']['invisible'][] = $state; + } + if ($this->multiple()) { + $form['pivot']['#states']['invisible'][] = $state; + } + if (empty($form['@type']['#default_value'])) { + $form['@type']['#default_value'] = 'Url'; + } + return $form; + } + + /** + * {@inheritdoc} + */ + public static function testValue() { + $items = []; + $keys = self::creativeWorkFormKeys('WebContent'); + foreach ($keys as $key) { + switch ($key) { + + case '@type': + $items[$key] = 'WebContent'; + break; + + case 'author': + $items[$key] = SchemaPersonOrgBase::testValue(); + break; + + case 'potentialAction': + $items[$key] = SchemaActionBase::testValue(); + break; + + default: + $items[$key] = parent::testDefaultValue(1, ''); + break; + + } + } + return $items; + } + +} diff --git a/src/Plugin/metatag/Tag/SchemaWebContentBase.php b/src/Plugin/metatag/Tag/SchemaWebContentBase.php new file mode 100644 index 0000000..83e752c --- /dev/null +++ b/src/Plugin/metatag/Tag/SchemaWebContentBase.php @@ -0,0 +1,86 @@ +value()); + + $input_values = [ + 'title' => $this->label(), + 'description' => $this->description(), + 'value' => $value, + '#required' => isset($element['#required']) ? $element['#required'] : FALSE, + 'visibility_selector' => $this->visibilitySelector(), + ]; + + $form = $this->creativeWorkForm($input_values); + + if (empty($this->multiple())) { + unset($form['pivot']); + } + + return $form; + } + + /** + * {@inheritdoc} + */ + public static function testValue() { + $items = []; + $keys = self::creativeWorkFormKeys('WebContent'); + foreach ($keys as $key) { + switch ($key) { + + case '@type': + $items[$key] = 'WebContent'; + break; + + case 'author': + $items[$key] = SchemaPersonOrgBase::testValue(); + break; + + case 'potentialAction': + $items[$key] = SchemaActionBase::testValue(); + break; + + default: + $items[$key] = parent::testDefaultValue(1, ''); + break; + + } + } + return $items; + } + + /** + * {@inheritdoc} + */ + public static function processedTestValue($items) { + foreach ($items as $key => $value) { + switch ($key) { + case 'author': + $items[$key] = SchemaPersonOrgBase::processedTestValue($items[$key]); + break; + + case 'potentialAction': + $items[$key] = SchemaActionBase::processedTestValue($items[$key]); + break; + + } + } + return $items; + } +} diff --git a/src/Plugin/metatag/Tag/SchemaWebContentTrait.php b/src/Plugin/metatag/Tag/SchemaWebContentTrait.php new file mode 100644 index 0000000..efe2636 --- /dev/null +++ b/src/Plugin/metatag/Tag/SchemaWebContentTrait.php @@ -0,0 +1,29 @@ +