-
Notifications
You must be signed in to change notification settings - Fork 9
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
sebastianthulin
merged 12 commits into
3.0/develop
from
feature/Ny-modul-Modal-CU-865cn09xb
Aug 7, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
624600c
(add) ACF fields for module Modal
annalinneajohansson 4f725c1
(add) New module "Modal"
annalinneajohansson 8092f5e
(add) Settings for modal and button
annalinneajohansson 4681910
(add) Add action to add noindex, nofollow meta tag on mod-modal-conte…
annalinneajohansson 4bef601
(feat) noindex no longer needed since we added publicly_queryable => …
annalinneajohansson de7c89b
(chore) Ran formatting on php code
annalinneajohansson 56e48f6
(feat) Changed the post type name to "modal-content" from "mod-modal-…
annalinneajohansson 163ef34
feat: Disallow the Modal block for the modal content post type
annalinneajohansson 2ca58f4
(add) Expanded isModularityPage() to also check modularity-options fo…
annalinneajohansson c1cba6d
Revert "(add) Expanded isModularityPage() to also check modularity-op…
annalinneajohansson f5ff435
Updated description
annalinneajohansson ed8dd61
Use Module class method for getting fields
annalinneajohansson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
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 | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be replaced with this option on module creation.
https://github.com/helsingborg-stad/Modularity/blob/3.0/develop/source/php/Module.php#L105
There was a problem hiding this comment.
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.