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

[5.1] Article Schemaorg plugin #3081

Closed
jgerman-bot opened this issue Jan 11, 2024 · 0 comments · Fixed by #3082
Closed

[5.1] Article Schemaorg plugin #3081

jgerman-bot opened this issue Jan 11, 2024 · 0 comments · Fixed by #3082

Comments

@jgerman-bot
Copy link

New language relevant PR in upstream repo: joomla/joomla-cms#42402 Here are the upstream changes:

Click to expand the diff!
diff --git a/administrator/components/com_admin/sql/updates/mysql/5.1.0-2023-11-28.sql b/administrator/components/com_admin/sql/updates/mysql/5.1.0-2023-11-28.sql
new file mode 100644
index 0000000000000..98c6889baaa47
--- /dev/null
+++ b/administrator/components/com_admin/sql/updates/mysql/5.1.0-2023-11-28.sql
@@ -0,0 +1,2 @@
+INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES
+(0, 'plg_schemaorg_article', 'plugin', 'article', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
diff --git a/administrator/components/com_admin/sql/updates/postgresql/5.1.0-2023-11-28.sql b/administrator/components/com_admin/sql/updates/postgresql/5.1.0-2023-11-28.sql
new file mode 100644
index 0000000000000..523b7057ecc3a
--- /dev/null
+++ b/administrator/components/com_admin/sql/updates/postgresql/5.1.0-2023-11-28.sql
@@ -0,0 +1,2 @@
+INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES
+(0, 'plg_schemaorg_article', 'plugin', 'article', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
diff --git a/administrator/language/en-GB/plg_schemaorg_article.ini b/administrator/language/en-GB/plg_schemaorg_article.ini
new file mode 100644
index 0000000000000..d4fd8dca6f197
--- /dev/null
+++ b/administrator/language/en-GB/plg_schemaorg_article.ini
@@ -0,0 +1,28 @@
+; Joomla! Project
+; (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
+; License GNU General Public License version 2 or later; see LICENSE.txt
+; Note : All ini files need to be saved as UTF-8
+
+PLG_SCHEMAORG_ARTICLE="Schema.org - Article"
+PLG_SCHEMAORG_ARTICLE_DESCRIPTION_LABEL="More information on the Schema.org Article Type can be found at <a href=\"https://schema.org/Article\" target=\"_blank\" rel=\"noopener noreferrer\">https://schema.org/Article</a>"
+PLG_SCHEMAORG_ARTICLE_FIELD_ADDRESS_LABEL="Address"
+PLG_SCHEMAORG_ARTICLE_FIELD_AUTHOR_LABEL="Author"
+PLG_SCHEMAORG_ARTICLE_FIELD_DATE_MODIFIED_LABEL="Date Modified"
+PLG_SCHEMAORG_ARTICLE_FIELD_DATE_PUBLISHED_LABEL="Date Published"
+PLG_SCHEMAORG_ARTICLE_FIELD_DESCRIPTION_LABEL="Description"
+PLG_SCHEMAORG_ARTICLE_FIELD_EMAIL_LABEL="Email"
+PLG_SCHEMAORG_ARTICLE_FIELD_GENERIC_FIELD_LABEL="Generic Field"
+PLG_SCHEMAORG_ARTICLE_FIELD_GENERIC_TITLE_LABEL="Title"
+PLG_SCHEMAORG_ARTICLE_FIELD_GENERIC_VALUE_LABEL="Value"
+PLG_SCHEMAORG_ARTICLE_FIELD_HEADLINE_LABEL="Headline"
+PLG_SCHEMAORG_ARTICLE_FIELD_IMAGE_LABEL="Image"
+PLG_SCHEMAORG_ARTICLE_FIELD_LOCALITY_LABEL="Locality"
+PLG_SCHEMAORG_ARTICLE_FIELD_LOGO_LABEL="Logo"
+PLG_SCHEMAORG_ARTICLE_FIELD_NAME_LABEL="Name"
+PLG_SCHEMAORG_ARTICLE_FIELD_ORGANIZATION_LABEL="Organization"
+PLG_SCHEMAORG_ARTICLE_FIELD_PERSON_LABEL="Person"
+PLG_SCHEMAORG_ARTICLE_FIELD_POSTAL_CODE_LABEL="Postal Code"
+PLG_SCHEMAORG_ARTICLE_FIELD_STREET_ADDRESS_LABEL="Street Address"
+PLG_SCHEMAORG_ARTICLE_FIELD_TYPE_LABEL="Type"
+PLG_SCHEMAORG_ARTICLE_FIELD_URL_LABEL="Url"
+PLG_SCHEMAORG_ARTICLE_XML_DESCRIPTION="Adds Article as a new schema type in existing schemas."
diff --git a/administrator/language/en-GB/plg_schemaorg_article.sys.ini b/administrator/language/en-GB/plg_schemaorg_article.sys.ini
new file mode 100644
index 0000000000000..c2d56801161fb
--- /dev/null
+++ b/administrator/language/en-GB/plg_schemaorg_article.sys.ini
@@ -0,0 +1,7 @@
+; Joomla! Project
+; (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
+; License GNU General Public License version 2 or later; see LICENSE.txt
+; Note : All ini files need to be saved as UTF-8
+
+PLG_SCHEMAORG_ARTICLE="Schema.org - Article"
+PLG_SCHEMAORG_ARTICLE_XML_DESCRIPTION="Adds Article as a new schema type in existing schemas."
diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql
index de2267be2bf7b..c34c49dd41e0a 100644
--- a/installation/sql/mysql/base.sql
+++ b/installation/sql/mysql/base.sql
@@ -333,13 +333,14 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
 (0, 'plg_quickicon_eos', 'plugin', 'eos', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 7, 0),
 (0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 1, 0),
 (0, 'plg_sampledata_multilang', 'plugin', 'multilang', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 2, 0),
-(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 1, 0),
-(0, 'plg_schemaorg_book', 'plugin', 'book', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 2, 0),
-(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 3, 0),
-(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 4, 0),
-(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 5, 0),
-(0, 'plg_schemaorg_recipe', 'plugin', 'recipe', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 6, 0),
-(0, 'plg_schemaorg_jobposting', 'plugin', 'jobposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 7, 0),
+(0, 'plg_schemaorg_article', 'plugin', 'article', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 1, 0),
+(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 2, 0),
+(0, 'plg_schemaorg_book', 'plugin', 'book', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 3, 0),
+(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 4, 0),
+(0, 'plg_schemaorg_jobposting', 'plugin', 'jobposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 5, 0),
+(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 6, 0),
+(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 7, 0),
+(0, 'plg_schemaorg_recipe', 'plugin', 'recipe', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 8, 0),
 (0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', '', 1, 0),
 (0, 'plg_system_actionlogs', 'plugin', 'actionlogs', 'system', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
 (0, 'plg_system_cache', 'plugin', 'cache', 'system', 0, 0, 1, 0, 1, '', '{"browsercache":"0","cachetime":"15"}', '', 3, 0),
diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql
index f18dca65ddbdd..435afc0ee2112 100644
--- a/installation/sql/postgresql/base.sql
+++ b/installation/sql/postgresql/base.sql
@@ -339,13 +339,14 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
 (0, 'plg_quickicon_eos', 'plugin', 'eos', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 7, 0),
 (0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 1, 0),
 (0, 'plg_sampledata_multilang', 'plugin', 'multilang', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 2, 0),
-(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 1, 0),
-(0, 'plg_schemaorg_book', 'plugin', 'book', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 2, 0),
-(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 3, 0),
-(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 4, 0),
-(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 5, 0),
-(0, 'plg_schemaorg_recipe', 'plugin', 'recipe', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 6, 0),
-(0, 'plg_schemaorg_jobposting', 'plugin', 'jobposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 7, 0),
+(0, 'plg_schemaorg_article', 'plugin', 'article', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 1, 0),
+(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 2, 0),
+(0, 'plg_schemaorg_book', 'plugin', 'book', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 3, 0),
+(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 4, 0),
+(0, 'plg_schemaorg_jobposting', 'plugin', 'jobposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 5, 0),
+(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 6, 0),
+(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 7, 0),
+(0, 'plg_schemaorg_recipe', 'plugin', 'recipe', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 8, 0),
 (0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', '', 1, 0),
 (0, 'plg_system_actionlogs', 'plugin', 'actionlogs', 'system', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
 (0, 'plg_system_cache', 'plugin', 'cache', 'system', 0, 0, 1, 0, 1, '', '{"browsercache":"0","cachetime":"15"}', '', 3, 0),
diff --git a/libraries/src/Extension/ExtensionHelper.php b/libraries/src/Extension/ExtensionHelper.php
index 3e0ac57e16aeb..8757e7616068f 100644
--- a/libraries/src/Extension/ExtensionHelper.php
+++ b/libraries/src/Extension/ExtensionHelper.php
@@ -277,6 +277,7 @@ class ExtensionHelper
         ['plugin', 'multilang', 'sampledata', 0],
 
         // Core plugin extensions - schemaorg
+        ['plugin', 'article', 'schemaorg', 0],
         ['plugin', 'blogposting', 'schemaorg', 0],
         ['plugin', 'book', 'schemaorg', 0],
         ['plugin', 'event', 'schemaorg', 0],
diff --git a/plugins/schemaorg/article/article.xml b/plugins/schemaorg/article/article.xml
new file mode 100644
index 0000000000000..0e38050623cdf
--- /dev/null
+++ b/plugins/schemaorg/article/article.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<extension type="plugin" group="schemaorg" method="upgrade">
+	<name>plg_schemaorg_article</name>
+	<author>Joomla! Project</author>
+	<creationDate>2024-01</creationDate>
+	<copyright>(C) 2024 Open Source Matters, Inc.</copyright>
+	<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
+	<authorEmail>admin@joomla.org</authorEmail>
+	<authorUrl>www.joomla.org</authorUrl>
+	<version>__DEPLOY_VERSION__</version>
+	<description>PLG_SCHEMAORG_ARTICLE_XML_DESCRIPTION</description>
+	<namespace path="src">Joomla\Plugin\Schemaorg\Article</namespace>
+	<files>
+		<folder plugin="article">services</folder>
+		<folder>src</folder>
+	</files>
+	<languages>
+		<language tag="en-GB">language/en-GB/plg_schemaorg_article.ini</language>
+		<language tag="en-GB">language/en-GB/plg_schemaorg_article.sys.ini</language>
+	</languages>
+	<config>
+		<fields name="params">
+			<fieldset name="basic">
+				<field
+					name="allowedlist"
+					type="SchemaorgComponentSections"
+					label="JSCHEMAORG_EXTENSION_ALLOWED_LABEL"
+					description="JSCHEMAORG_EXTENSION_ALLOWED_DESCRIPTION"
+					multiple="multiple"
+					layout="joomla.form.field.list-fancy-select"
+				/>
+				<field
+					name="forbiddenlist"
+					type="SchemaorgComponentSections"
+					label="JSCHEMAORG_EXTENSION_FORBIDDEN_LABEL"
+					description="JSCHEMAORG_EXTENSION_FORBIDDEN_DESCRIPTION"
+					multiple="multiple"
+					layout="joomla.form.field.list-fancy-select"
+				/>
+			</fieldset>
+		</fields>
+	</config>
+</extension>
diff --git a/plugins/schemaorg/article/forms/schemaorg.xml b/plugins/schemaorg/article/forms/schemaorg.xml
new file mode 100644
index 0000000000000..df464544719a1
--- /dev/null
+++ b/plugins/schemaorg/article/forms/schemaorg.xml
@@ -0,0 +1,199 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form>
+	<fields name="schema">
+		<fieldset
+			name="schema"
+			label="PLG_SYSTEM_SCHEMA_FIELD_SCHEMA_LABEL"
+		>
+			<field
+				name="Article"
+				type="subform"
+				showon="schemaType:Article"
+			>
+				<form>
+
+					<field
+						name="@type"
+						type="hidden"
+						default="Article"
+					/>
+
+					<field
+						name="noteArticle"
+						type="note"
+						description="PLG_SCHEMAORG_ARTICLE_DESCRIPTION_LABEL"
+						class="alert alert-info w-100"
+					/>
+
+					<field
+						name="image"
+						type="media"
+						label="PLG_SCHEMAORG_ARTICLE_FIELD_IMAGE_LABEL"
+					/>
+
+					<field
+						name="headline"
+						type="text"
+						label="PLG_SCHEMAORG_ARTICLE_FIELD_HEADLINE_LABEL"
+						filter="string"
+						size="30"
+					/>
+
+					<field
+						name="description"
+						type="text"
+						label="PLG_SCHEMAORG_ARTICLE_FIELD_DESCRIPTION_LABEL"
+						filter="string"
+					/>
+
+					<field
+						name="author"
+						type="subform"
+						label="PLG_SCHEMAORG_ARTICLE_FIELD_AUTHOR_LABEL"
+						>
+						<form>
+
+							<field
+								name="@type"
+								type="list"
+								label="PLG_SCHEMAORG_ARTICLE_FIELD_TYPE_LABEL"
+								default="person"
+								>
+								<option value="person">PLG_SCHEMAORG_ARTICLE_FIELD_PERSON_LABEL</option>
+								<option value="organization">PLG_SCHEMAORG_ARTICLE_FIELD_ORGANIZATION_LABEL</option>
+							</field>
+
+							<field
+								name="name"
+								type="text"
+								label="PLG_SCHEMAORG_ARTICLE_FIELD_NAME_LABEL"
+								filter="string"
+							/>
+
+							<field
+								name="url"
+								type="url"
+								label="PLG_SCHEMAORG_ARTICLE_FIELD_URL_LABEL"
+								filter="url"
+								validate="url"
+							/>
+
+							<field
+								name="logo"
+								type="subform"
+								label="PLG_SCHEMAORG_ARTICLE_FIELD_LOGO_LABEL"
+								showon="@type:organization"
+							>
+								<form>
+
+									<field
+										name="@type"
+										type="hidden"
+										default="ImageObject"
+									/>
+
+									<field
+										name="url"
+										type="media"
+										label="PLG_SCHEMAORG_ARTICLE_FIELD_URL_LABEL"
+									/>
+
+								</form>
+							</field>
+
+							<field
+								name="email"
+								type="email"
+								label="PLG_SCHEMAORG_ARTICLE_FIELD_EMAIL_LABEL"
+								validate="email"
+							/>
+
+							<field
+								name="address"
+								type="subform"
+								label="PLG_SCHEMAORG_ARTICLE_FIELD_ADDRESS_LABEL"
+							>
+								<form>
+
+									<field
+										name="@type"
+										type="hidden"
+										default="PostalAddress"
+									/>
+
+									<field
+										name="addressLocality"
+										type="text"
+										label="PLG_SCHEMAORG_ARTICLE_FIELD_LOCALITY_LABEL"
+									/>
+
+									<field
+										name="postalCode"
+										type="text"
+										label="PLG_SCHEMAORG_ARTICLE_FIELD_POSTAL_CODE_LABEL"
+									/>
+
+									<field
+										name="streetAddress"
+										type="text"
+										label="PLG_SCHEMAORG_ARTICLE_FIELD_STREET_ADDRESS_LABEL"
+									/>
+
+								</form>
+							</field>
+
+						</form>
+					</field>
+
+					<field
+						name="datePublished"
+						type="calendar"
+						label="PLG_SCHEMAORG_ARTICLE_FIELD_DATE_PUBLISHED_LABEL"
+						class="input-small"
+						filter="user_utc"
+						showtime="false"
+						todaybutton="true"
+						translateformat="true"
+					/>
+
+					<field
+						name="dateModified"
+						type="calendar"
+						label="PLG_SCHEMAORG_ARTICLE_FIELD_DATE_MODIFIED_LABEL"
+						class="input-small"
+						filter="user_utc"
+						showtime="false"
+						todaybutton="true"
+						translateformat="true"
+					/>
+
+					<field
+						name="genericField"
+						type="subform"
+						label="PLG_SCHEMAORG_ARTICLE_FIELD_GENERIC_FIELD_LABEL"
+						multiple="true"
+					>
+						<form>
+							<field
+								name="genericTitle"
+								type="text"
+								label="PLG_SCHEMAORG_ARTICLE_FIELD_GENERIC_TITLE_LABEL"
+								filter="string"
+								size="30"
+							/>
+							<field
+								name="genericValue"
+								type="text"
+								filter="string"
+								size="30"
+								label="PLG_SCHEMAORG_ARTICLE_FIELD_GENERIC_VALUE_LABEL"
+							/>
+						</form>
+
+					</field>
+
+				</form>
+			</field>
+		</fieldset>
+	</fields>
+</form>
diff --git a/plugins/schemaorg/article/services/provider.php b/plugins/schemaorg/article/services/provider.php
new file mode 100644
index 0000000000000..fe01212232e01
--- /dev/null
+++ b/plugins/schemaorg/article/services/provider.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * @package     Joomla.Plugin
+ * @subpackage  Schemaorg.article
+ *
+ * @copyright   (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
+ * @license     GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+\defined('_JEXEC') or die;
+
+use Joomla\CMS\Extension\PluginInterface;
+use Joomla\CMS\Factory;
+use Joomla\CMS\Plugin\PluginHelper;
+use Joomla\DI\Container;
+use Joomla\DI\ServiceProviderInterface;
+use Joomla\Event\DispatcherInterface;
+use Joomla\Plugin\Schemaorg\Article\Extension\Article;
+
+return new class () implements ServiceProviderInterface {
+    /**
+     * Registers the service provider with a DI container.
+     *
+     * @param   Container  $container  The DI container.
+     *
+     * @return  void
+     *
+     * @since   __DEPLOY_VERSION__
+     */
+    public function register(Container $container)
+    {
+        $container->set(
+            PluginInterface::class,
+            function (Container $container) {
+                $dispatcher = $container->get(DispatcherInterface::class);
+                $plugin     = new Article(
+                    $dispatcher,
+                    (array) PluginHelper::getPlugin('schemaorg', 'article')
+                );
+                $plugin->setApplication(Factory::getApplication());
+
+                return $plugin;
+            }
+        );
+    }
+};
diff --git a/plugins/schemaorg/article/src/Extension/Article.php b/plugins/schemaorg/article/src/Extension/Article.php
new file mode 100644
index 0000000000000..71f3cc9d94383
--- /dev/null
+++ b/plugins/schemaorg/article/src/Extension/Article.php
@@ -0,0 +1,102 @@
+<?php
+
+/**
+ * @package     Joomla.Plugin
+ * @subpackage  Schemaorg.article
+ *
+ * @copyright   (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
+ * @license     GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+namespace Joomla\Plugin\Schemaorg\Article\Extension;
+
+use Joomla\CMS\Event\Plugin\System\Schemaorg\BeforeCompileHeadEvent;
+use Joomla\CMS\Plugin\CMSPlugin;
+use Joomla\CMS\Schemaorg\SchemaorgPluginTrait;
+use Joomla\CMS\Schemaorg\SchemaorgPrepareDateTrait;
+use Joomla\CMS\Schemaorg\SchemaorgPrepareImageTrait;
+use Joomla\Event\Priority;
+use Joomla\Event\SubscriberInterface;
+
+// phpcs:disable PSR1.Files.SideEffects
+\defined('_JEXEC') or die;
+// phpcs:enable PSR1.Files.SideEffects
+
+/**
+ * Schemaorg Plugin
+ *
+ * @since  __DEPLOY_VERSION__
+ */
+final class Article extends CMSPlugin implements SubscriberInterface
+{
+    use SchemaorgPluginTrait;
+    use SchemaorgPrepareDateTrait;
+    use SchemaorgPrepareImageTrait;
+
+    /**
+     * Load the language file on instantiation.
+     *
+     * @var    boolean
+     * @since  __DEPLOY_VERSION__
+     */
+    protected $autoloadLanguage = true;
+
+    /**
+     * The name of the schema form
+     *
+     * @var   string
+     * @since __DEPLOY_VERSION__
+     */
+    protected $pluginName = 'Article';
+
+    /**
+     * Returns an array of events this subscriber will listen to.
+     *
+     * @return  array
+     *
+     * @since   __DEPLOY_VERSION__
+     */
+    public static function getSubscribedEvents(): array
+    {
+        return [
+            'onSchemaPrepareForm'       => 'onSchemaPrepareForm',
+            'onSchemaBeforeCompileHead' => ['onSchemaBeforeCompileHead', Priority::BELOW_NORMAL],
+        ];
+    }
+
+    /**
+     * Cleanup all Article types
+     *
+     * @param   BeforeCompileHeadEvent  $event  The given event
+     *
+     * @return  void
+     *
+     * @since   __DEPLOY_VERSION__
+     */
+    public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event): void
+    {
+        $schema = $event->getSchema();
+
+        $graph = $schema->get('@graph');
+
+        foreach ($graph as &$entry) {
+            if (!isset($entry['@type']) || $entry['@type'] !== 'Article') {
+                continue;
+            }
+
+            if (!empty($entry['datePublished'])) {
+                $entry['datePublished'] = $this->prepareDate($entry['datePublished']);
+            }
+
+            if (!empty($entry['dateModified'])) {
+                $entry['dateModified'] = $this->prepareDate($entry['dateModified']);
+            }
+
+            if (!empty($entry['image'])) {
+                $entry['image'] = $this->prepareImage($entry['image']);
+            }
+        }
+
+        $schema->set('@graph', $graph);
+    }
+}
@tecpromotion tecpromotion linked a pull request Jan 11, 2024 that will close this issue
2 tasks
tecpromotion added a commit to tecpromotion/joomla that referenced this issue Jan 14, 2024
zero-24 pushed a commit that referenced this issue Jan 17, 2024
* add two new files

* fix #3081

* ndash

* Update administrator/language/de-DE/plg_schemaorg_article.ini

Co-authored-by: Christian Heel <66922325+heelc29@users.noreply.github.com>

* Update administrator/language/de-DE/plg_schemaorg_article.ini

Co-authored-by: Christian Heel <66922325+heelc29@users.noreply.github.com>

* Update administrator/language/de-DE/plg_schemaorg_article.ini

Co-authored-by: Christian Heel <66922325+heelc29@users.noreply.github.com>

---------

Co-authored-by: Christian Heel <66922325+heelc29@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants