- md5
- c1718af207755bff3b673f85ebe5b592
- sha1
- 5f1d593355774846e27ed98204d9617a99634cbe
- sha256
- e9ab81e1532030e0c62e80d03713c86e7bcb4cff86d31223ebf6f7fc63606b94
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
<?php
/**
* @package Joomla.Plugin
* @subpackage Schemaorg.book
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
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\Priority;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Schemaorg Plugin
*
* @since 5.0.0
*/
final class Book extends CMSPlugin implements SubscriberInterface
{
use SchemaorgPluginTrait;
use SchemaorgPrepareDateTrait;
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 5.0.0
*/
protected $autoloadLanguage = true;
/**
* The name of the schema form
*
* @var string
* @since 5.0.0
*/
protected $pluginName = 'Book';
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onSchemaPrepareForm' => 'onSchemaPrepareForm',
'onSchemaBeforeCompileHead' => ['onSchemaBeforeCompileHead', Priority::BELOW_NORMAL],
];
}
/**
* Cleanup all Book types
*
* @param BeforeCompileHeadEvent $event The given event
*
* @return void
*
* @since 5.0.0
*/
public function onSchemaBeforeCompileHead(BeforeCompileHeadEvent $event): void
{
$schema = $event->getSchema();
$graph = $schema->get('@graph');
foreach ($graph as &$entry) {
if (!isset($entry['@type']) || $entry['@type'] !== 'Book') {
continue;
}
if (!empty($entry['datePublished'])) {
$entry['datePublished'] = $this->prepareDate($entry['datePublished']);
}
}
$schema->set('@graph', $graph);
}
}
The same content is in 152 releases, Joomla 5.0.0-alpha4 to 6.2.1-rc1. See them all, or every version of this file.