FEATURES Handling block extra options

This commit is contained in:
Antoine M 2026-02-13 15:32:16 +01:00
parent 237bf0ef31
commit f19995471c
3 changed files with 85 additions and 59 deletions

View File

@ -9,7 +9,11 @@
"description": "Example block scaffolded with Create Block tool.", "description": "Example block scaffolded with Create Block tool.",
"example": {}, "example": {},
"supports": { "supports": {
"html": false "html": false,
"color": {
"background": true,
"text": true
}
}, },
"textdomain": "dernieres-dynamiques", "textdomain": "dernieres-dynamiques",
"editorScript": "file:./index.js", "editorScript": "file:./index.js",
@ -21,6 +25,10 @@
"displayType": { "displayType": {
"type": "string", "type": "string",
"default": "grid" "default": "grid"
},
"showTableOfContents": {
"type": "boolean",
"default": true
} }
} }
} }

View File

@ -11,12 +11,16 @@ import "./editor.scss";
import ServerSideRender from "@wordpress/server-side-render"; import ServerSideRender from "@wordpress/server-side-render";
export default function Edit({ attributes, setAttributes }) { export default function Edit({ attributes, setAttributes }) {
const { displayType } = attributes; const { displayType, showTableOfContents = true } = attributes;
function onDisplayTypeChange(value) { function onDisplayTypeChange(value) {
setAttributes({ displayType: value }); setAttributes({ displayType: value });
} }
function onShowTableOfContentsChange(value) {
setAttributes({ showTableOfContents: !showTableOfContents });
}
return ( return (
<> <>
<InspectorControls> <InspectorControls>
@ -31,6 +35,11 @@ export default function Edit({ attributes, setAttributes }) {
<ToggleGroupControlOption label="Slider" value="slider" /> <ToggleGroupControlOption label="Slider" value="slider" />
<ToggleGroupControlOption label="Grille" value="grid" /> <ToggleGroupControlOption label="Grille" value="grid" />
</ToggleGroupControl> </ToggleGroupControl>
<CheckboxControl
label="Afficher la table des matières"
checked={showTableOfContents}
onChange={onShowTableOfContentsChange}
/>
</PanelBody> </PanelBody>
</InspectorControls> </InspectorControls>
<div {...useBlockProps({ className: "alignfull" })}> <div {...useBlockProps({ className: "alignfull" })}>

View File

@ -1,6 +1,13 @@
<?php <?php
$displayType = $attributes['displayType'] ?? 'grid'; $displayType = $attributes['displayType'] ?? 'grid';
$variantLocation = $attributes['variantLocation'] ?? 'carhop'; $variantLocation = $attributes['variantLocation'] ?? 'carhop';
$showTableOfContents = $attributes['showTableOfContents'] ?? true;
$backgroundColor = $attributes['backgroundColor'] ?? null;
$backgroundColorHex = get_color_hex_from_slug($backgroundColor) ?? null;
$hasLightBackground = is_color_light($backgroundColorHex);
$backgroundColorClass = $hasLightBackground ? 'block-dernieres-dynamiques--has-light-bg' : 'block-dernieres-dynamiques--has-dark-bg';
$current_blog_id = get_current_blog_id(); $current_blog_id = get_current_blog_id();
switch_to_blog(2); switch_to_blog(2);
@ -23,7 +30,7 @@ $issue_related_articles = get_field('articles', $last_issue->ID);
?> ?>
<section class="block-dernieres-dynamiques content-section block-dernieres-dynamiques--<?php echo $variantLocation; ?> alignfull"> <section <?php echo get_block_wrapper_attributes(array('class' => 'block-dernieres-dynamiques content-section block-dernieres-dynamiques--' . $variantLocation . ' alignfull ' . $backgroundColorClass)); ?>>
<div class="block-dernieres-dynamiques__inner"> <div class="block-dernieres-dynamiques__inner">
<div class="block-dernieres-dynamiques__header"> <div class="block-dernieres-dynamiques__header">
<h2 class="block-title"> <h2 class="block-title">
@ -84,6 +91,8 @@ $issue_related_articles = get_field('articles', $last_issue->ID);
</div> </div>
</div> </div>
<?php if ($showTableOfContents) : ?>
<div class="related-articles"> <div class="related-articles">
<h3 class="related-articles__title"> <h3 class="related-articles__title">
Table des matières Table des matières
@ -157,7 +166,7 @@ $issue_related_articles = get_field('articles', $last_issue->ID);
</div> </div>
<?php endif; ?>
</div> </div>
</section> </section>