Skip to content

Commit 9385231

Browse files
authored
Merge pull request joomla#19 from joomla-projects/person
Person Plugin
2 parents c193bc3 + 11ee575 commit 9385231

File tree

10 files changed

+379
-2
lines changed

10 files changed

+379
-2
lines changed

administrator/components/com_admin/sql/updates/mysql/4.2.3-2022-12-10.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
1717
(0, 'plg_schemaorg_book', 'plugin', 'book', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
1818
(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
1919
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
20-
(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
20+
(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
21+
(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);

administrator/components/com_admin/sql/updates/postgresql/4.2.3-2022-12-10.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
1717
(0, 'plg_schemaorg_book', 'plugin', 'book', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
1818
(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
1919
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
20-
(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
20+
(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
21+
(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PLG_SCHEMAORG_PERSON_DESCRIPTION_LABEL="A Schema.org Type <a href=\"https://schema.org/Person\" target=\"_blank\">More information</a>"
2+
PLG_SCHEMAORG_PERSON_FIELD_ADDRESS_LABEL="Address"
3+
PLG_SCHEMAORG_PERSON_FIELD_EMAIL_LABEL="Email"
4+
PLG_SCHEMAORG_PERSON_FIELD_GENERIC_FIELD_LABEL="Generic Field"
5+
PLG_SCHEMAORG_PERSON_FIELD_GENERIC_TITLE_LABEL="Title"
6+
PLG_SCHEMAORG_PERSON_FIELD_GENERIC_VALUE_LABEL="Value"
7+
PLG_SCHEMAORG_PERSON_FIELD_LOCALITY_LABEL="Locality"
8+
PLG_SCHEMAORG_PERSON_FIELD_NAME_LABEL="Name"
9+
PLG_SCHEMAORG_PERSON_FIELD_POSTAL_CODE_LABEL="Postal Code"
10+
PLG_SCHEMAORG_PERSON_FIELD_STREET_ADDRESS_LABEL="Street Address"
11+
PLG_SCHEMAORG_PERSON_FIELD_URL_LABEL="URL"
12+
PLG_SCHEMAORG_PERSON_XML_DESCRIPTION="Adds Person as a new schema type in existing schemas"
13+
PLG_SCHEMAORG_PERSON="Schema.org Person Plugin"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PLG_SCHEMAORG_PERSON_XML_DESCRIPTION="Adds Person as a new schema type in existing schemas"
2+
PLG_SCHEMAORG_PERSON="Schema.org Person Plugin"

installation/sql/mysql/base.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
330330
(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
331331
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
332332
(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
333+
(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
333334
(0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', '', 1, 0),
334335
(0, 'plg_system_actionlogs', 'plugin', 'actionlogs', 'system', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
335336
(0, 'plg_system_cache', 'plugin', 'cache', 'system', 0, 0, 1, 0, 1, '', '{"browsercache":"0","cachetime":"15"}', '', 3, 0),

installation/sql/postgresql/base.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
336336
(0, 'plg_schemaorg_blogposting', 'plugin', 'blogposting', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
337337
(0, 'plg_schemaorg_organization', 'plugin', 'organization', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
338338
(0, 'plg_schemaorg_event', 'plugin', 'event', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
339+
(0, 'plg_schemaorg_person', 'plugin', 'person', 'schemaorg', 0, 1, 1, 0, 0, '', '{}', '', 0, 0),
339340
(0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', '', 1, 0),
340341
(0, 'plg_system_actionlogs', 'plugin', 'actionlogs', 'system', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
341342
(0, 'plg_system_cache', 'plugin', 'cache', 'system', 0, 0, 1, 0, 1, '', '{"browsercache":"0","cachetime":"15"}', '', 3, 0),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<extension type="plugin" group="schemaorg" method="upgrade">
3+
<name>plg_schemaorg_person</name>
4+
<author>Joomla! Project</author>
5+
<creationDate>June 2022</creationDate>
6+
<copyright>(C) 2022 Open Source Matters, Inc.</copyright>
7+
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
8+
<authorEmail>[email protected]</authorEmail>
9+
<authorUrl>www.joomla.org</authorUrl>
10+
<version>__DEPLOY_VERSION__</version>
11+
<description>PLG_SCHEMAORG_PERSON_XML_DESCRIPTION</description>
12+
<namespace path="src">Joomla\Plugin\Schemaorg\Person</namespace>
13+
<files>
14+
<folder plugin="person">services</folder>
15+
<folder>src</folder>
16+
</files>
17+
<languages>
18+
<language tag="en-GB">language/en-GB/plg_schemaorg_person.ini</language>
19+
<language tag="en-GB">language/en-GB/plg_schemaorg_person.sys.ini</language>
20+
</languages>
21+
<config>
22+
<fields name="params">
23+
<fieldset name="basic">
24+
<field
25+
name="allowedlist"
26+
type="SchemaorgComponentSections"
27+
label="JSCHEMAORG_EXTENSION_ALLOWED_LABEL"
28+
description="JSCHEMAORG_EXTENSION_ALLOWED_DESCRIPTION"
29+
multiple="multiple"
30+
layout="joomla.form.field.list-fancy-select"
31+
/>
32+
<field
33+
name="forbiddenlist"
34+
type="SchemaorgComponentSections"
35+
label="JSCHEMAORG_EXTENSION_FORBIDDEN_LABEL"
36+
description="JSCHEMAORG_EXTENSION_FORBIDDEN_DESCRIPTION"
37+
multiple="multiple"
38+
layout="joomla.form.field.list-fancy-select"
39+
/>
40+
</fieldset>
41+
</fields>
42+
</config>
43+
</extension>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Plugin
5+
* @subpackage Schemaorg.person
6+
*
7+
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
defined('_JEXEC') or die;
12+
13+
use Joomla\CMS\Extension\PluginInterface;
14+
use Joomla\CMS\Factory;
15+
use Joomla\CMS\Plugin\PluginHelper;
16+
use Joomla\DI\Container;
17+
use Joomla\DI\ServiceProviderInterface;
18+
use Joomla\Event\DispatcherInterface;
19+
use Joomla\Plugin\Schemaorg\Person\Extension\Person;
20+
21+
return new class implements ServiceProviderInterface
22+
{
23+
/**
24+
* Registers the service provider with a DI container.
25+
*
26+
* @param Container $container The DI container.
27+
*
28+
* @return void
29+
*
30+
* @since 4.2.0
31+
*/
32+
public function register(Container $container)
33+
{
34+
$container->set(
35+
PluginInterface::class,
36+
function (Container $container) {
37+
$dispatcher = $container->get(DispatcherInterface::class);
38+
$plugin = new Person(
39+
$dispatcher,
40+
(array) PluginHelper::getPlugin('schemaorg', 'person')
41+
);
42+
43+
$plugin->setApplication(Factory::getApplication());
44+
45+
return $plugin;
46+
}
47+
);
48+
}
49+
};
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Plugin
5+
*
6+
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
9+
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
10+
*/
11+
12+
namespace Joomla\Plugin\Schemaorg\Person\Extension;
13+
14+
use Joomla\CMS\Application\CMSApplicationInterface;
15+
use Joomla\CMS\Form\Form;
16+
use Joomla\CMS\Plugin\CMSPlugin;
17+
use Joomla\CMS\Schemaorg\SchemaorgPluginTrait;
18+
use Joomla\CMS\Event\AbstractEvent;
19+
use Joomla\Event\SubscriberInterface;
20+
21+
// phpcs:disable PSR1.Files.SideEffects
22+
\defined('_JEXEC') or die;
23+
// phpcs:enable PSR1.Files.SideEffects
24+
25+
/**
26+
* Schemaorg Plugin
27+
*
28+
* @since 4.0.0
29+
*/
30+
final class Person extends CMSPlugin implements SubscriberInterface
31+
{
32+
use SchemaorgPluginTrait;
33+
34+
/**
35+
* @var \Joomla\Database\DatabaseDriver
36+
*
37+
*/
38+
protected $db;
39+
40+
/**
41+
* Load the language file on instantiation.
42+
*
43+
* @var boolean
44+
* @since 4.0.0
45+
*/
46+
protected $autoloadLanguage = true;
47+
48+
/**
49+
* Loads the CMS Application for direct access
50+
*
51+
* @var CMSApplicationInterface
52+
* @since 4.0.0
53+
*/
54+
protected $app;
55+
56+
/**
57+
* The name of the supported name to check against
58+
*
59+
* @var string
60+
* @since 4.0.0
61+
*/
62+
protected $supportFunctionality = 'core.state';
63+
64+
/**
65+
* The name of the schema form
66+
*
67+
* @var string
68+
* @since 4.0.0
69+
*/
70+
protected $pluginName = 'Person';
71+
72+
/**
73+
* Returns an array of events this subscriber will listen to.
74+
*
75+
* @return array
76+
*
77+
* @since 4.0.0
78+
*/
79+
public static function getSubscribedEvents(): array
80+
{
81+
return [
82+
'onSchemaPrepareData' => 'onSchemaPrepareData',
83+
'onSchemaPrepareForm' => 'onSchemaPrepareForm',
84+
'onSchemaAfterSave' => 'onSchemaAfterSave',
85+
'onSchemaBeforeCompileHead' => 'pushSchema',
86+
];
87+
}
88+
89+
/**
90+
* Update existing schema form with data from database
91+
*
92+
* @param $data The form to be altered.
93+
*
94+
* @return boolean
95+
*/
96+
public function onSchemaPrepareData(AbstractEvent $event)
97+
{
98+
$context = $event->getArgument('context');
99+
100+
if (!$this->isSupported($context) || !$this->isSchemaSupported($event)) {
101+
return false;
102+
}
103+
104+
$this->updateSchemaForm($event);
105+
106+
return true;
107+
}
108+
109+
/**
110+
* Add a new option to the schema type in the article editing page
111+
*
112+
* @param Form $form The form to be altered.
113+
*
114+
* @return boolean
115+
*/
116+
public function onSchemaPrepareForm(AbstractEvent $event)
117+
{
118+
$form = $event->getArgument('subject');
119+
$context = $form->getName();
120+
121+
if (!$this->isSupported($context)) {
122+
return false;
123+
}
124+
125+
$this->addSchemaType($event);
126+
127+
//Load the form fields
128+
$form->loadFile(JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name . '/src/forms/schemaorg.xml');
129+
130+
return true;
131+
}
132+
133+
/**
134+
* Saves the schema to the database
135+
*
136+
* @param AbstractEvent $event
137+
*
138+
* @return boolean
139+
*/
140+
public function onSchemaAfterSave(AbstractEvent $event)
141+
{
142+
$data = $event->getArgument('data')->toArray();
143+
$form = $data['schema']['schemaType'];
144+
145+
if ($form != $this->pluginName) {
146+
return false;
147+
}
148+
149+
$this->storeSchemaToStandardLocation($event);
150+
151+
return true;
152+
}
153+
}
154+

0 commit comments

Comments
 (0)