Skip to content

Commit

Permalink
Merge branch 'main' into test/html-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink authored Jan 17, 2024
2 parents a81659f + 0d86c32 commit 6c3e1d6
Show file tree
Hide file tree
Showing 39 changed files with 1,874 additions and 636 deletions.
15 changes: 15 additions & 0 deletions assets/source/3.0/js/admin/optionsReading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
document.addEventListener('DOMContentLoaded', () => {
const postsPerPageInput: HTMLInputElement | null = document.querySelector('#posts_per_page');

if (postsPerPageInput) {
let parentElement: HTMLElement | null = postsPerPageInput.parentElement;

while (parentElement && parentElement.nodeName !== 'TR') {
parentElement = parentElement.parentElement;
}

if (parentElement) {
parentElement.style.display = 'none';
}
}
});
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@
"Municipio\\": "library/"
}
},
"version": "3.59.0"
"version": "3.61.2"
}
18 changes: 4 additions & 14 deletions library/Admin/Acf/LocationRulesContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,8 @@ public function match($rule, $screen, $field_group)
}

// Compare the post attribute to rule value.
$contentType = \Municipio\Helper\ContentType::getContentType($type, true);

if (is_object($contentType)) {
$result = ($contentType->getKey() === $rule['value']);
$returnResult = $result;
// Return result taking into account the operator type.
if ($rule['operator'] == '!=') {
$returnResult = !$result;
}
} else {
$returnResult = false;
}
return $returnResult;
$hasContentType = \Municipio\Helper\ContentType::hasContentType($rule['value'], $type);

return $hasContentType;
}
}
}
36 changes: 33 additions & 3 deletions library/Admin/Gutenberg/Gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,45 @@

namespace Municipio\Admin\Gutenberg;

/**
* Class Gutenberg
*
*
*/
class Gutenberg
{
/**
* Constructor method.
*
* Initializes the Gutenberg class and adds necessary filters.
*/
public function __construct()
{
add_filter("use_block_editor_for_post_type", array($this, 'activateGutenbergEditor'), 10, 2);
add_filter('allowed_block_types', [$this,'additionalAllowedBlocks'], 10, 1);
}

public function activateGutenbergEditor($useBlockEditor, $postType) {

/**
*
* @param array $allowed_block_types The array of allowed block types.
* @return array The updated array of allowed block types.
*/
public function additionalAllowedBlocks($allowed_block_types)
{
$allowed_block_types[] = 'core/embed';
return $allowed_block_types;
}
/**
* Activates the Gutenberg editor based on the specified conditions.
*
* @param bool $useBlockEditor Whether to use the block editor.
* @param string $postType The post type.
* @return bool The updated value of $useBlockEditor.
*/

public function activateGutenbergEditor($useBlockEditor, $postType)
{

global $post;

Expand Down Expand Up @@ -46,5 +77,4 @@ public function activateGutenbergEditor($useBlockEditor, $postType) {

return $useBlockEditor;
}

}
}
29 changes: 16 additions & 13 deletions library/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,27 @@ public function __construct()
$resourcePostType->addHooks();

// Set up registry.

$resourceRegistry = new \Municipio\Content\ResourceFromApi\ResourceRegistry();
$resourceRegistry->registerResources();

add_action('init', function () use ($resourceRegistry) {

$resourceRegistry->registerResources();

foreach ($resourceRegistry->getByType(ResourceType::POST_TYPE) as $resource) {
$registrar = new PostTypeFromResource($resource);
$registrar->register();
}

foreach ($resourceRegistry->getByType(ResourceType::TAXONOMY) as $resource) {
$registrar = new TaxonomyFromResource($resource);
$registrar->register();
}
});

// Make resources available to the helper class.
ResourceFromApiHelper::initialize($resourceRegistry);

// Register post types from resources.
foreach ($resourceRegistry->getByType(ResourceType::POST_TYPE) as $resource) {
$registrar = new PostTypeFromResource($resource);
$registrar->register();
}

// Register taxonomies from resources.
foreach ($resourceRegistry->getByType(ResourceType::TAXONOMY) as $resource) {
$registrar = new TaxonomyFromResource($resource);
$registrar->register();
}

// Add hooks for modifiers. Modifiers are used to modify the output of resources through filters and actions.
$modifiersHelper = new ModifiersHelper($resourceRegistry);
$hooksAdder = new HooksAdder($resourceRegistry, $modifiersHelper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public function __construct(ResourceRegistryInterface $resourceRegistry)
/**
* Handle the modification of the page data.
*
* @param array|null $pageData The page data.
* @param mixed $pageData The page data.
* @param mixed $queriedObject The queried object.
* @param mixed $queriedObjectData The queried object data.
* @return array|null The modified page data.
* @return mixed The modified page data.
*/
public function handle(?array $pageData, $queriedObject, $queriedObjectData): ?array
public function handle($pageData, $queriedObject, $queriedObjectData)
{
if (is_null($pageData) || !is_a($queriedObject, 'WP_Post')) {
return $pageData;
Expand Down
9 changes: 2 additions & 7 deletions library/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,7 @@ public function __construct()
$this->data['hasSideMenu'] = $this->hasSideMenu();
$this->data['hasMainMenu'] = $this->hasMainMenu();

//Structured data
$this->data['structuredData'] = \Municipio\Helper\Data::getStructuredData(
$this->data['postType'],
$this->getPageID()
);

$this->data['structuredData'] = \Municipio\Helper\Data::prepareStructuredData([]);
//Notice storage
$this->data['notice'] = [];

Expand Down Expand Up @@ -945,4 +940,4 @@ public function globalToLocal($global, $local = null)

return true;
}
}
}
6 changes: 5 additions & 1 deletion library/Controller/ContentType/ContentTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ public function getView(): string
{
return "content-type-{$this->getKey()}";
}
}
public function getStructuredData(int $postId) : array
{
return [];
}
}
33 changes: 16 additions & 17 deletions library/Controller/ContentType/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@
class Event extends ContentTypeFactory implements ContentTypeComplexInterface
{

protected $secondaryContentType = [];
public $secondaryContentType = [];

public function __construct()
{
$this->key = 'event';
$this->label = __('Event', 'municipio');

parent::__construct($this->key, $this->label);

$this->addSecondaryContentType(new Place());

}

public function addHooks(): void {

// Append structured data to use for schema.org markup
add_filter('Municipio/StructuredData', [$this, 'appendStructuredData'], 10, 3);
public function addHooks() : void
{

}
/**
* addSecondaryContentType
Expand All @@ -54,20 +52,17 @@ public function addSecondaryContentType(ContentTypeComponentInterface $contentTy
*
* @return array The updated structured data.
*/
public function appendStructuredData(array $structuredData, string $postType, int $postId): array
public function getStructuredData(int $postId): array
{
if (empty($postId)) {
return $structuredData;
}

$post = \Municipio\Helper\Post::preparePostObject(get_post($postId));

// Build the schema.org event data
$eventData = [
'@type' => 'Event',
'name' => $post->postTitle,
'description' => $post->postExcerpt,
'offers' => [],
'@type' => 'Event',
'name' => $post->postTitle,
'description' => $post->postExcerpt,
'offers' => [],
];

$eventMeta = get_post_meta($postId);
Expand Down Expand Up @@ -128,7 +123,11 @@ public function appendStructuredData(array $structuredData, string $postType, in
}
}

if(empty($eventData['offers'])) {
unset($eventData['offers']);
}
// Append the event data to the structured data
return array_merge($eventData, $structuredData);
return $eventData;
}
}

}
73 changes: 20 additions & 53 deletions library/Controller/ContentType/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Municipio\Controller\ContentType;

use Municipio\Helper\ContentType as ContentTypeHelper;

/**
* Class Person
*
Expand All @@ -10,74 +12,39 @@
class Person extends ContentTypeFactory
{

protected $secondaryContentType = [];
public $secondaryContentType = [];

public function __construct()
{
$this->key = 'person';
$this->label = __('Person', 'municipio');

parent::__construct($this->key, $this->label);
}

public function init(): void
{
$this->addHooks();
}

public function addHooks(): void {
// Append structured data for schema.org markup
add_filter('Municipio/StructuredData', [$this, 'appendStructuredData'], 10, 3);


}
/**
* Appends structured data for a Person to the given array.
*
* @param array $structuredData The array to append the structured data to.
* @param Person $person The Person object to generate the structured data for.
*
* @return array The updated array with the Person structured data appended.
*/
public function appendStructuredData(array $structuredData, string $postType, int $postId): array
public function getStructuredData(int $postId) : array
{
if (empty($postId)) {
return $structuredData;
}

$additionalData = [
'@context' => 'https://schema.org',
'@type' => 'Person',
$structuredData = [
'@type' => 'Person',
'name' => get_the_title($postId),
];

// Define the available properties for the Person schema
$properties = apply_filters(
'Municipio/ContentType/structuredDataProperties',
[
'name',
'jobTitle',
'email',
'telephone'
],
$postId
);

// Iterate over each property and try to fetch the corresponding meta data from the post
foreach ($properties as $property) {
$propertyValue =
apply_filters(
"Municipio/ContentType/structuredDataProperty/{$property}",
null,
$postId
);

if (is_null($propertyValue)) {
$propertyValue = \Municipio\Helper\WP::getField($property, $postId);
}

$additionalData[$property] =
apply_filters(
"Municipio/ContentType/structuredDataProperty/{$property}/value",
$propertyValue,
$postId
);
}
$meta = [
'jobTitle',
'email',
'telephone'
];

return array_merge($structuredData, $additionalData);
return ContentTypeHelper::getStructuredData($postId, $structuredData, $meta);

}
}
}
Loading

0 comments on commit 6c3e1d6

Please sign in to comment.