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

feature/Ny modul Modal CU 865cn09xb #441

Merged
merged 12 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modularity.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
'mod-divider' => 'group_62816d604ae46',
'mod-all' => 'group_636e424039120',
'mod-subscribe' => 'group_641c51b765f4b',
'mod-modal' => 'group_64a29154aa972',

# Deactivated
'mod-social' => 'group_56dedc26e5327',
Expand Down
2,588 changes: 2,588 additions & 0 deletions source/php/AcfFields/json/mod-modal.json

Large diffs are not rendered by default.

2,591 changes: 2,591 additions & 0 deletions source/php/AcfFields/php/mod-modal.php

Large diffs are not rendered by default.

114 changes: 114 additions & 0 deletions source/php/Module/Modal/Modal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace Modularity\Module\Modal;

use Municipio\Helper\Post;

class Modal extends \Modularity\Module
{
public $slug = 'modal';
public $supports = array();

public function init()
{
$this->nameSingular = __("Modal", 'modularity');
$this->namePlural = __("Modals", 'modularity');
$this->description = __("Outputs a button and the content of a selected Modal Content post into a modal, accessible by clicking on the button.", 'modularity');
$this->postType = 'modal-content';

add_action('init', [$this, 'registerPostType'], 99);
add_filter('allowed_block_types_all', array($this, 'disallowBlockType'), 10, 2);
}

public function data(): array
{

$fields = $this->getFields();
$data = [];

// Modal button
$data['buttonIcon'] = $fields['button']['material_icon'] ?? false;
$data['buttonText'] = $fields['button']['text'] ?? false;
$data['buttonSize'] = $fields['button']['size'] ?? 'md';
$data['buttonStyle'] = $fields['button']['style'] ?? 'outlined';
$data['buttonColor'] = $fields['button']['color'] ?? 'primary';
$data['reversePosition'] = (bool) \intval($fields['button']['reverse_position']) ?? false;

// Modal settings
$data['useModalContentTitle'] = (bool) \intval($fields['modal']['use_modal_content_title']) ?? false;
$data['modalIsPanel'] = (bool) \intval($fields['modal']['is_panel']) ?? false;
$data['modalSize'] = $fields['modal']['size'] ?? 'md';
$data['modalPadding'] = $fields['modal']['padding'] ?? 3;
$data['modalBorderRadius'] = $fields['modal']['border_radius'] = 'md';

// Modal content
$modalContentPost = \Municipio\Helper\Post::preparePostObject(
$fields['modal']['content']
);
$data['modalId'] = $modalContentPost->ID ?? 0;
$data['modalContentTitle'] = $modalContentPost->postTitleFiltered ?? false;
$data['modalContent'] = $modalContentPost->postContentFiltered ?? false;

return $data;
}

public function registerPostType()
{
$args = [
'supports' => [ 'title', 'editor', 'revisions' ],
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 40,
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'has_archive' => false,
'show_in_rest' => true,
'publicly_queryable' => false,
'capability_type' => 'page',
'labels' => [
'all_items' => __('All Modal Contents', 'modularity'),
'name' => __('Modal Content', 'modularity'),
'menu_name' => __('Modal Content', 'modularity'),
'add_new_item' => __('Add New Modal Content', 'modularity'),
'add_new' => __('Add Modal Content', 'modularity'),
'new_item' => __('New Modal Content', 'modularity'),
'edit_item' => __('Edit Modal Content', 'modularity'),
'update_item' => __('Update Modal Content', 'modularity'),
'view_item' => __('View Modal Content', 'modularity'),
'view_items' => __('View Modal Contents', 'modularity'),
'search_items' => __('Search For Modal Content', 'modularity'),
],
];
register_post_type($this->postType, $args);
}

/**
* Disallow the Modal block for the current post type;
* modals inside of modals can possibly create infinite loops.
*
* @param array $allowedBlockTypes The allowed block types.
* @param object $editorContext The editor context.
* @return array The updated allowed block types.
*/
public function disallowBlockType($allowedBlockTypes, $editorContext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@annalinneajohansson annalinneajohansson Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following your thought here; can you please explain? The module is meant to be available as a block, but not on the modal-content post type. I'm not finding any way to detect the post type currently being edited whilst registering the module.

{
if ($this->postType === $editorContext->post->post_type) {
unset($allowedBlockTypes['acf/modal']);
}
return $allowedBlockTypes;
}
/**
* Available "magic" methods for modules:
* init() What to do on initialization
* data() Use to send data to view (return array)
* style() Enqueue style only when module is used on page
* script Enqueue script only when module is used on page
* adminEnqueue() Enqueue scripts for the module edit/add page in admin
* template() Return the view template (blade) the module should use when displayed
*/
}
33 changes: 33 additions & 0 deletions source/php/Module/Modal/views/modal.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@if (!$hideTitle && !empty($postTitle))
@typography([
'id' => 'mod-modal-' . $ID . '-label',
'element' => 'h2',
'variant' => 'h2',
'classList' => ['module-title']
])
{!! $postTitle !!}
@endtypography
@endif

@button([
'href' => '',
'text' => $buttonText,
'icon' => $buttonIcon,
'size' => $buttonSize,
'color' => $buttonColor,
'style' => $buttonStyle,
'reversePositions' => $reversePosition,
'classList' => ['open-modal'],
'attributeList' => ['data-open' => 'modal-' . $modalId],
])
@endbutton
@modal([
'isPanel' => $modalIsPanel,
'size' => $modalSize,
'padding' => $modalPadding,
'borderRadius' => $modalBorderRadius,
'heading' => $useModalContentTitle ? $modalContentTitle : false,
'id' => 'modal-' . $modalId
])
{!! $modalContent !!}
@endmodal
12 changes: 6 additions & 6 deletions source/php/ModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function getRegistered($getBundled = true)

return apply_filters('Modularity/Modules', self::$registered);
}

/**
* Get enabled modules id: s
* @return array
Expand Down Expand Up @@ -184,7 +184,7 @@ public function init()
require_once $source;
$class = $namespace . '\\' . $module;
$class = new $class();

$this->register($class, $path);
self::$blockManager->classes[$class->slug] = $class;
}
Expand Down Expand Up @@ -296,8 +296,8 @@ public function register($class, string $path = '')

if (file_exists($plugin)) {
require_once $plugin;
} elseif (file_exists(MODULARITY_PATH . 'plugins/'. $plugin)) {
require_once MODULARITY_PATH . 'plugins/'. $plugin;
} elseif (file_exists(MODULARITY_PATH . 'plugins/' . $plugin)) {
require_once MODULARITY_PATH . 'plugins/' . $plugin;
}
}
}
Expand Down Expand Up @@ -656,10 +656,10 @@ public function listTableColumnContent($column, $postId)
switch ($column) {
case 'description':
$description = get_post_meta($postId, 'module-description', true);
echo !empty($description) ? $description: '';
echo !empty($description) ? $description : '';
break;

case 'usage':
case 'usage':
$usage = self::getModuleUsage($postId, 3);

if (count($usage->data) == 0) {
Expand Down
Loading