diff --git a/libraries/src/Event/CoreEventAware.php b/libraries/src/Event/CoreEventAware.php index 1cf47a31481db..9a2ca8184f704 100644 --- a/libraries/src/Event/CoreEventAware.php +++ b/libraries/src/Event/CoreEventAware.php @@ -100,6 +100,11 @@ trait CoreEventAware 'onAjaxWebauthnInitcreate' => PlgSystemWebauthnAjaxInitCreate::class, 'onAjaxWebauthnLogin' => PlgSystemWebauthnAjaxLogin::class, 'onAjaxWebauthnSavelabel' => PlgSystemWebauthnAjaxSaveLabel::class, + // Plugin: System, Schemaorg + 'onSchemaBeforeCompileHead' => Plugin\System\Schemaorg\BeforeCompileHeadEvent::class, + 'onSchemaPrepareData' => Plugin\System\Schemaorg\PrepareDataEvent::class, + 'onSchemaPrepareForm' => Plugin\System\Schemaorg\PrepareFormEvent::class, + 'onSchemaPrepareSave' => Plugin\System\Schemaorg\PrepareSaveEvent::class, // Extensions 'onBeforeExtensionBoot' => BeforeExtensionBootEvent::class, 'onAfterExtensionBoot' => AfterExtensionBootEvent::class, diff --git a/libraries/src/Event/Plugin/System/Schemaorg/BeforeCompileHeadEvent.php b/libraries/src/Event/Plugin/System/Schemaorg/BeforeCompileHeadEvent.php new file mode 100644 index 0000000000000..eabacd1af8a13 --- /dev/null +++ b/libraries/src/Event/Plugin/System/Schemaorg/BeforeCompileHeadEvent.php @@ -0,0 +1,102 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\CMS\Event\Plugin\System\Schemaorg; + +use Joomla\CMS\Event\AbstractImmutableEvent; +use Joomla\Registry\Registry; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * Class for SchemaBeforeCompileHeadEvent event + * Example: + * new BeforeCompileHeadEvent('onSchemaBeforeCompileHead', ['subject' => $schema, 'context' => 'com_example.example']); + * + * @since __DEPLOY_VERSION__ + */ +class BeforeCompileHeadEvent extends AbstractImmutableEvent +{ + /** + * Constructor. + * + * @param string $name The event name. + * @param array $arguments The event arguments. + * + * @throws \BadMethodCallException + * + * @since __DEPLOY_VERSION__ + */ + public function __construct($name, array $arguments = []) + { + if (!\array_key_exists('subject', $arguments)) { + throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided"); + } + + if (!\array_key_exists('context', $arguments)) { + throw new \BadMethodCallException("Argument 'context' of event {$name} is required but has not been provided"); + } + + parent::__construct($name, $arguments); + } + + /** + * Setter for the subject argument. + * + * @param Registry $value The value to set + * + * @return Registry + * + * @since __DEPLOY_VERSION__ + */ + protected function setSubject(Registry $value): Registry + { + return $value; + } + + /** + * Setter for the context argument. + * + * @param string $value The value to set + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + protected function setContext(string $value): string + { + return $value; + } + + /** + * Getter for the schema argument. + * + * @return Registry + * + * @since __DEPLOY_VERSION__ + */ + public function getSchema(): Registry + { + return $this->arguments['subject']; + } + + /** + * Getter for the context argument. + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + public function getContext(): string + { + return $this->arguments['context']; + } +} diff --git a/libraries/src/Event/Plugin/System/Schemaorg/PrepareDataEvent.php b/libraries/src/Event/Plugin/System/Schemaorg/PrepareDataEvent.php new file mode 100644 index 0000000000000..8cce990a598df --- /dev/null +++ b/libraries/src/Event/Plugin/System/Schemaorg/PrepareDataEvent.php @@ -0,0 +1,101 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\CMS\Event\Plugin\System\Schemaorg; + +use Joomla\CMS\Event\AbstractImmutableEvent; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * Class for SchemaPrepareDataEvent event + * Example: + * new PrepareDataEvent('onSchemaPrepareData', ['subject' => $data, 'context' => 'com_example.example']); + * + * @since __DEPLOY_VERSION__ + */ +class PrepareDataEvent extends AbstractImmutableEvent +{ + /** + * Constructor. + * + * @param string $name The event name. + * @param array $arguments The event arguments. + * + * @throws \BadMethodCallException + * + * @since __DEPLOY_VERSION__ + */ + public function __construct($name, array $arguments = []) + { + if (!\array_key_exists('subject', $arguments)) { + throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided"); + } + + if (!\array_key_exists('context', $arguments)) { + throw new \BadMethodCallException("Argument 'context' of event {$name} is required but has not been provided"); + } + + parent::__construct($name, $arguments); + } + + /** + * Setter for the subject argument. + * + * @param object $value The value to set + * + * @return object + * + * @since __DEPLOY_VERSION__ + */ + protected function setSubject(object $value): object + { + return $value; + } + + /** + * Setter for the context argument. + * + * @param string $value The value to set + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + protected function setContext(string $value): string + { + return $value; + } + + /** + * Getter for the data argument. + * + * @return object + * + * @since __DEPLOY_VERSION__ + */ + public function getData(): object + { + return $this->arguments['subject']; + } + + /** + * Getter for the context argument. + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + public function getContext(): string + { + return $this->arguments['context']; + } +} diff --git a/libraries/src/Event/Plugin/System/Schemaorg/PrepareFormEvent.php b/libraries/src/Event/Plugin/System/Schemaorg/PrepareFormEvent.php new file mode 100644 index 0000000000000..1eb0f945d6d09 --- /dev/null +++ b/libraries/src/Event/Plugin/System/Schemaorg/PrepareFormEvent.php @@ -0,0 +1,72 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\CMS\Event\Plugin\System\Schemaorg; + +use Joomla\CMS\Event\AbstractImmutableEvent; +use Joomla\CMS\Form\Form; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * Class for SchemaPrepareFormEvent event + * Example: + * new PrepareFormEvent('onSchemaPrepareForm', ['subject' => $form]); + * + * @since __DEPLOY_VERSION__ + */ +class PrepareFormEvent extends AbstractImmutableEvent +{ + /** + * Constructor. + * + * @param string $name The event name. + * @param array $arguments The event arguments. + * + * @throws \BadMethodCallException + * + * @since __DEPLOY_VERSION__ + */ + public function __construct($name, array $arguments = []) + { + if (!\array_key_exists('subject', $arguments)) { + throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided"); + } + + parent::__construct($name, $arguments); + } + + /** + * Setter for the subject argument. + * + * @param Form $value The value to set + * + * @return Form + * + * @since __DEPLOY_VERSION__ + */ + protected function setSubject(Form $value): Form + { + return $value; + } + + /** + * Getter for the form argument. + * + * @return Form + * + * @since __DEPLOY_VERSION__ + */ + public function getForm(): Form + { + return $this->arguments['subject']; + } +} diff --git a/libraries/src/Event/Plugin/System/Schemaorg/PrepareSaveEvent.php b/libraries/src/Event/Plugin/System/Schemaorg/PrepareSaveEvent.php new file mode 100644 index 0000000000000..b9bb5d8a48af9 --- /dev/null +++ b/libraries/src/Event/Plugin/System/Schemaorg/PrepareSaveEvent.php @@ -0,0 +1,192 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\CMS\Event\Plugin\System\Schemaorg; + +use Joomla\CMS\Event\AbstractImmutableEvent; +use Joomla\CMS\Table\TableInterface; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * Class for SchemaPrepareSaveEvent event + * Example: + * new PrepareFormEvent('onSchemaPrepareForm', ['subject' => $subject, 'context' => $context, 'item' => $table, 'isNew' => $isNew, 'schema' => $schema]); + * + * @since __DEPLOY_VERSION__ + */ +class PrepareSaveEvent extends AbstractImmutableEvent +{ + /** + * Constructor. + * + * @param string $name The event name. + * @param array $arguments The event arguments. + * + * @throws \BadMethodCallException + * + * @since __DEPLOY_VERSION__ + */ + public function __construct($name, array $arguments = []) + { + if (!\array_key_exists('subject', $arguments)) { + throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided"); + } + + if (!\array_key_exists('context', $arguments)) { + throw new \BadMethodCallException("Argument 'context' of event {$name} is required but has not been provided"); + } + + if (!\array_key_exists('item', $arguments)) { + throw new \BadMethodCallException("Argument 'item' of event {$name} is required but has not been provided"); + } + + if (!\array_key_exists('isNew', $arguments)) { + throw new \BadMethodCallException("Argument 'isNew' of event {$name} is required but has not been provided"); + } + + if (!\array_key_exists('schema', $arguments)) { + throw new \BadMethodCallException("Argument 'schema' of event {$name} is required but has not been provided"); + } + + parent::__construct($name, $arguments); + } + + /** + * Setter for the subject argument. + * + * @param object $value The value to set + * + * @return object + * + * @since __DEPLOY_VERSION__ + */ + protected function setSubject(object $value): object + { + return $value; + } + + /** + * Setter for the context argument. + * + * @param string $value The value to set + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + protected function setContext(string $value): string + { + return $value; + } + + /** + * Setter for the item argument. + * + * @param TableInterface $value The value to set + * + * @return TableInterface + * + * @since __DEPLOY_VERSION__ + */ + protected function setItem(TableInterface $value): TableInterface + { + return $value; + } + + /** + * Setter for the isNew argument. + * + * @param boolean $value The value to set + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + protected function setIsNew(bool $value): bool + { + return $value; + } + + /** + * Setter for the schema argument. + * + * @param array $value The value to set + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + protected function setSchema(array $value): array + { + return $value; + } + + /** + * Getter for the data argument. + * + * @return object + * + * @since __DEPLOY_VERSION__ + */ + public function getData(): object + { + return $this->arguments['subject']; + } + + /** + * Getter for the context argument. + * + * @return string + * + * @since __DEPLOY_VERSION__ + */ + public function getContext(): string + { + return $this->arguments['context']; + } + + /** + * Getter for the item argument. + * + * @return TableInterface + * + * @since __DEPLOY_VERSION__ + */ + public function getItem(): TableInterface + { + return $this->arguments['item']; + } + + /** + * Getter for the isNew argument. + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public function getIsNew(): bool + { + return $this->arguments['isNew']; + } + + /** + * Getter for the schema argument. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function getSchema(): array + { + return $this->arguments['schema']; + } +} diff --git a/libraries/src/Schemaorg/SchemaorgPluginTrait.php b/libraries/src/Schemaorg/SchemaorgPluginTrait.php index 1e00d9d308411..2d54a3f5f89a1 100755 --- a/libraries/src/Schemaorg/SchemaorgPluginTrait.php +++ b/libraries/src/Schemaorg/SchemaorgPluginTrait.php @@ -9,8 +9,8 @@ namespace Joomla\CMS\Schemaorg; +use Joomla\CMS\Event\Plugin\System\Schemaorg\PrepareFormEvent; use Joomla\CMS\Form\Field\ListField; -use Joomla\Event\EventInterface; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -23,15 +23,6 @@ */ trait SchemaorgPluginTrait { - /** - * Define all fields which are media type to clean them - * - * @var array - */ - protected $imageFields = [ - 'image', - ]; - /** * Returns an array of events this subscriber will listen to. * @@ -49,19 +40,19 @@ public static function getSubscribedEvents(): array /** * Add a new option to schemaType list field in schema form * - * @param EventInterface $event + * @param PrepareFormEvent $event * - * @return boolean + * @return void * * @since 5.0.0 */ - protected function addSchemaType(EventInterface $event) + protected function addSchemaType(PrepareFormEvent $event): void { - $form = $event->getArgument('subject'); + $form = $event->getForm(); $name = $this->pluginName; if (!$form || !$name) { - return false; + return; } $schemaType = $form->getField('schemaType', 'schema'); @@ -69,43 +60,43 @@ protected function addSchemaType(EventInterface $event) if ($schemaType instanceof ListField) { $schemaType->addOption($name, ['value' => $name]); } - - return true; } /** - * Add a new option to the schema type in the item editing page + * Add a new option to the schema type in the item editing page * - * @param EventInterface $event The form to be altered. + * @param PrepareFormEvent $event The form to be altered. * - * @return boolean + * @return void + * + * @since 5.0.0 */ - public function onSchemaPrepareForm(EventInterface $event) + public function onSchemaPrepareForm(PrepareFormEvent $event): void { - $form = $event->getArgument('subject'); + $form = $event->getForm(); $context = $form->getName(); if (!$this->isSupported($context)) { - return false; + return; } $this->addSchemaType($event); - //Load the form fields + // Load the form fields if (is_file(JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name . '/forms/schemaorg.xml')) { $form->loadFile(JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name . '/forms/schemaorg.xml'); } - - return true; } /** - * To create an array from repeatable text field data + * To create an array from repeatable text field data * - * @param array $schema Schema form - * @param array $repeatableFields Names of all the Repeatable fields + * @param array $schema Schema form + * @param array $repeatableFields Names of all the Repeatable fields + * + * @return array * - * @return array + * @since 5.0.0 */ protected function convertToArray(array $schema, array $repeatableFields) { @@ -147,7 +138,7 @@ protected function convertToArray(array $schema, array $repeatableFields) * * @param string $context * - * @return boolean + * @return boolean * * @since 5.0.0 */ @@ -172,9 +163,11 @@ protected function isSupported($context) /** * Check if the context is listed in the allowed or forbidden lists and return the result. * - * @param string $context Context to check + * @param string $context Context to check * * @return boolean + * + * @since 5.0.0 */ protected function checkAllowedAndForbiddenlist($context) { diff --git a/plugins/content/joomla/src/Extension/Joomla.php b/plugins/content/joomla/src/Extension/Joomla.php index 6337c33ca3458..fd0ae5e0dd73f 100644 --- a/plugins/content/joomla/src/Extension/Joomla.php +++ b/plugins/content/joomla/src/Extension/Joomla.php @@ -12,6 +12,7 @@ use Joomla\CMS\Cache\CacheControllerFactory; use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Event\Plugin\System\Schemaorg\BeforeCompileHeadEvent; use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Language; @@ -25,7 +26,6 @@ use Joomla\Component\Workflow\Administrator\Table\WorkflowTable; use Joomla\Database\DatabaseAwareTrait; use Joomla\Database\ParameterType; -use Joomla\Event\EventInterface; use Joomla\Registry\Registry; use Joomla\Utilities\ArrayHelper; @@ -219,20 +219,22 @@ public function onContentBeforeChangeState($context, $pks, $value) /** * Add autogenerated schema data for content and contacts * - * @param EventInterface $event The event object + * @param BeforeCompileHeadEvent $event The event object * - * @return void + * @return void + * + * @since 5.0.0 */ - public function onSchemaBeforeCompileHead(EventInterface $event) + public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event): void { if (!$this->getApplication()->isClient('site')) { return; } - $context = $event->getArgument('context'); - $schema = $event->getArgument('subject'); + $context = $event->getContext(); + $schema = $event->getSchema(); - list($extension, $view, $id) = explode('.', $context); + [$extension, $view, $id] = explode('.', $context); if ($extension === 'com_content' && $this->params->get('schema_content', 1)) { $this->injectContentSchema($context, $schema); @@ -256,7 +258,7 @@ private function injectContentSchema(string $context, Registry $schema) $app = $this->getApplication(); $db = $this->getDatabase(); - list($extension, $view, $id) = explode('.', $context); + [$extension, $view, $id] = explode('.', $context); // Check if there is already a schema for the item, then skip it $mySchema = $schema->toArray(); @@ -481,7 +483,7 @@ private function injectContactSchema(string $context, Registry $schema) $app = $this->getApplication(); $db = $this->getDatabase(); - list($extension, $view, $id) = explode('.', $context); + [$extension, $view, $id] = explode('.', $context); // Check if there is already a schema for the item, then skip it $mySchema = $schema->toArray(); diff --git a/plugins/schemaorg/blogposting/src/Extension/BlogPosting.php b/plugins/schemaorg/blogposting/src/Extension/BlogPosting.php index 2872ac5414451..8f0d281a471b4 100755 --- a/plugins/schemaorg/blogposting/src/Extension/BlogPosting.php +++ b/plugins/schemaorg/blogposting/src/Extension/BlogPosting.php @@ -10,11 +10,11 @@ namespace Joomla\Plugin\Schemaorg\BlogPosting\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\Event; use Joomla\Event\Priority; use Joomla\Event\SubscriberInterface; @@ -67,15 +67,15 @@ public static function getSubscribedEvents(): array /** * Cleanup all BlogPosting types * - * @param Event $event The given event + * @param BeforeCompileHeadEvent $event The given event * - * @return void + * @return void * * @since __DEPLOY_VERSION__ */ - public function onSchemaBeforeCompileHead(Event $event) + public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event): void { - $schema = $event->getArgument('subject'); + $schema = $event->getSchema(); $graph = $schema->get('@graph'); diff --git a/plugins/schemaorg/book/src/Extension/Book.php b/plugins/schemaorg/book/src/Extension/Book.php index 3515e7ddb8464..1c4a9c9c4dcc6 100755 --- a/plugins/schemaorg/book/src/Extension/Book.php +++ b/plugins/schemaorg/book/src/Extension/Book.php @@ -10,10 +10,10 @@ namespace Joomla\Plugin\Schemaorg\Book\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\Event\Event; use Joomla\Event\Priority; use Joomla\Event\SubscriberInterface; @@ -65,15 +65,15 @@ public static function getSubscribedEvents(): array /** * Cleanup all Book types * - * @param Event $event The given event + * @param BeforeCompileHeadEvent $event The given event * - * @return void + * @return void * * @since __DEPLOY_VERSION__ */ - public function onSchemaBeforeCompileHead(Event $event) + public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event): void { - $schema = $event->getArgument('subject'); + $schema = $event->getSchema(); $graph = $schema->get('@graph'); diff --git a/plugins/schemaorg/event/src/Extension/Event.php b/plugins/schemaorg/event/src/Extension/Event.php index 07c81f93f0cb6..eacb8bbe43272 100755 --- a/plugins/schemaorg/event/src/Extension/Event.php +++ b/plugins/schemaorg/event/src/Extension/Event.php @@ -10,11 +10,11 @@ namespace Joomla\Plugin\Schemaorg\Event\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\Event as EventEvent; use Joomla\Event\Priority; use Joomla\Event\SubscriberInterface; @@ -67,15 +67,15 @@ public static function getSubscribedEvents(): array /** * Cleanup all Event types * - * @param Event $event The given event + * @param BeforeCompileHeadEvent $event The given event * - * @return void + * @return void * * @since __DEPLOY_VERSION__ */ - public function onSchemaBeforeCompileHead(EventEvent $event) + public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event): void { - $schema = $event->getArgument('subject'); + $schema = $event->getSchema(); $graph = $schema->get('@graph'); diff --git a/plugins/schemaorg/jobposting/src/Extension/JobPosting.php b/plugins/schemaorg/jobposting/src/Extension/JobPosting.php index deba868429458..919e3c314af93 100755 --- a/plugins/schemaorg/jobposting/src/Extension/JobPosting.php +++ b/plugins/schemaorg/jobposting/src/Extension/JobPosting.php @@ -10,10 +10,10 @@ namespace Joomla\Plugin\Schemaorg\JobPosting\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\Event\Event; use Joomla\Event\Priority; use Joomla\Event\SubscriberInterface; @@ -65,15 +65,15 @@ public static function getSubscribedEvents(): array /** * Cleanup all JobPosting types * - * @param Event $event The given event + * @param BeforeCompileHeadEvent $event The given event * - * @return void + * @return void * * @since __DEPLOY_VERSION__ */ - public function onSchemaBeforeCompileHead(Event $event) + public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event) { - $schema = $event->getArgument('subject'); + $schema = $event->getSchema(); $graph = $schema->get('@graph'); diff --git a/plugins/schemaorg/recipe/src/Extension/Recipe.php b/plugins/schemaorg/recipe/src/Extension/Recipe.php index 0307e074ef572..7021e1e7b3dc3 100755 --- a/plugins/schemaorg/recipe/src/Extension/Recipe.php +++ b/plugins/schemaorg/recipe/src/Extension/Recipe.php @@ -10,11 +10,11 @@ namespace Joomla\Plugin\Schemaorg\Recipe\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\SchemaorgPrepareDurationTrait; -use Joomla\Event\Event; use Joomla\Event\Priority; use Joomla\Event\SubscriberInterface; @@ -67,15 +67,15 @@ public static function getSubscribedEvents(): array /** * Cleanup all Recipe types * - * @param Event $event The given event + * @param BeforeCompileHeadEvent $event The given event * - * @return void + * @return void * * @since __DEPLOY_VERSION__ */ - public function onSchemaBeforeCompileHead(Event $event) + public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event) { - $schema = $event->getArgument('subject'); + $schema = $event->getSchema(); $graph = $schema->get('@graph'); diff --git a/plugins/system/schemaorg/src/Extension/Schemaorg.php b/plugins/system/schemaorg/src/Extension/Schemaorg.php index da3dd9a592a59..9999b826916c9 100644 --- a/plugins/system/schemaorg/src/Extension/Schemaorg.php +++ b/plugins/system/schemaorg/src/Extension/Schemaorg.php @@ -10,8 +10,11 @@ namespace Joomla\Plugin\System\Schemaorg\Extension; -use Joomla\CMS\Event\AbstractEvent; use Joomla\CMS\Event\Model; +use Joomla\CMS\Event\Plugin\System\Schemaorg\BeforeCompileHeadEvent; +use Joomla\CMS\Event\Plugin\System\Schemaorg\PrepareDataEvent; +use Joomla\CMS\Event\Plugin\System\Schemaorg\PrepareFormEvent; +use Joomla\CMS\Event\Plugin\System\Schemaorg\PrepareSaveEvent; use Joomla\CMS\Helper\ModuleHelper; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; @@ -119,9 +122,9 @@ public function onContentPrepareData(Model\PrepareDataEvent $event) } $dispatcher = $this->getDispatcher(); - $event = AbstractEvent::create('onSchemaPrepareData', [ - 'context' => $context, + $event = new PrepareDataEvent('onSchemaPrepareData', [ 'subject' => $data, + 'context' => $context, ]); PluginHelper::importPlugin('schemaorg', null, true, $dispatcher); @@ -170,7 +173,7 @@ public function onContentPrepareForm(Model\PrepareFormEvent $event) } $dispatcher = $this->getDispatcher(); - $event = AbstractEvent::create('onSchemaPrepareForm', [ + $event = new PrepareFormEvent('onSchemaPrepareForm', [ 'subject' => $form, ]); @@ -186,7 +189,6 @@ public function onContentPrepareForm(Model\PrepareFormEvent $event) * @return void * * @since 5.0.0 - * */ public function onContentAfterSave(Model\AfterSaveEvent $event) { @@ -244,9 +246,9 @@ public function onContentAfterSave(Model\AfterSaveEvent $event) } $dispatcher = $this->getDispatcher(); - $event = AbstractEvent::create('onSchemaPrepareSave', [ - 'context' => $context, + $event = new PrepareSaveEvent('onSchemaPrepareSave', [ 'subject' => $entry, + 'context' => $context, 'item' => $table, 'isNew' => $isNew, 'schema' => $data['schema'], @@ -269,9 +271,11 @@ public function onContentAfterSave(Model\AfterSaveEvent $event) /** * This event is triggered before the framework creates the Head section of the Document * + * @return void + * * @since 5.0.0 */ - public function onBeforeCompileHead() + public function onBeforeCompileHead(): void { $app = $this->getApplication(); $baseType = $this->params->get('baseType'); @@ -423,9 +427,9 @@ public function onBeforeCompileHead() $schema->loadArray($baseSchema); $dispatcher = $this->getDispatcher(); - $event = AbstractEvent::create('onSchemaBeforeCompileHead', [ - 'context' => $context . '.' . $itemId, + $event = new BeforeCompileHeadEvent('onSchemaBeforeCompileHead', [ 'subject' => $schema, + 'context' => $context . '.' . $itemId, ]); PluginHelper::importPlugin('schemaorg', null, true, $dispatcher);