FEATURES Handling block extra options
This commit is contained in:
parent
237bf0ef31
commit
f19995471c
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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" })}>
|
||||||
|
|
|
||||||
|
|
@ -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,80 +91,82 @@ $issue_related_articles = get_field('articles', $last_issue->ID);
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="related-articles">
|
<?php if ($showTableOfContents) : ?>
|
||||||
<h3 class="related-articles__title">
|
|
||||||
Table des matières
|
<div class="related-articles">
|
||||||
</h3>
|
<h3 class="related-articles__title">
|
||||||
|
Table des matières
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
|
||||||
<div class="article-caroussel article-caroussel--<?php echo $displayType; ?>">
|
<div class="article-caroussel article-caroussel--<?php echo $displayType; ?>">
|
||||||
|
|
||||||
<?php if ($displayType === 'grid') : ?>
|
<?php if ($displayType === 'grid') : ?>
|
||||||
|
|
||||||
<?php foreach ($issue_related_articles as $article) : ?>
|
<?php foreach ($issue_related_articles as $article) : ?>
|
||||||
<?php
|
<?php
|
||||||
get_template_part('template-parts/dynamiques/article-card', null, array(
|
get_template_part('template-parts/dynamiques/article-card', null, array(
|
||||||
'ID' => $article->ID,
|
'ID' => $article->ID,
|
||||||
|
|
||||||
));
|
));
|
||||||
?>
|
?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<!-- <button class="related-articles__show-all">
|
<!-- <button class="related-articles__show-all">
|
||||||
Tout afficher
|
Tout afficher
|
||||||
</button> -->
|
</button> -->
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|
||||||
<div class="article-caroussel__slider">
|
<div class="article-caroussel__slider">
|
||||||
<?php if ($issue_related_articles && is_array($issue_related_articles)) : ?>
|
<?php if ($issue_related_articles && is_array($issue_related_articles)) : ?>
|
||||||
|
|
||||||
|
|
||||||
<div class="swiper dernieres-dynamiques-swiper">
|
<div class="swiper dernieres-dynamiques-swiper">
|
||||||
<div class="swiper-wrapper">
|
<div class="swiper-wrapper">
|
||||||
<?php foreach ($issue_related_articles as $article) : ?>
|
<?php foreach ($issue_related_articles as $article) : ?>
|
||||||
|
|
||||||
<?php get_template_part('template-parts/dynamiques/article-card', null, array(
|
<?php get_template_part('template-parts/dynamiques/article-card', null, array(
|
||||||
'ID' => $article->ID,
|
'ID' => $article->ID,
|
||||||
'isSwiperSlide' => true,
|
'isSwiperSlide' => true,
|
||||||
'showCover' => true,
|
'showCover' => true,
|
||||||
)) ?>
|
)) ?>
|
||||||
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="swiper-pagination-fraction"></div>
|
|
||||||
<div class="swiper-pagination"></div>
|
|
||||||
|
|
||||||
<div class="swiper-controls">
|
|
||||||
<div class="swiper-button-prev">
|
|
||||||
<?php
|
|
||||||
$previous_arrow_icon = get_template_directory() . '/resources/img/elements/carhop-slider-previous.svg';
|
|
||||||
if (file_exists($previous_arrow_icon)) {
|
|
||||||
echo file_get_contents($previous_arrow_icon);
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="swiper-button-next">
|
|
||||||
<?php
|
<div class="swiper-pagination-fraction"></div>
|
||||||
$next_arrow_icon = get_template_directory() . '/resources/img/elements/carhop-slider-next.svg';
|
<div class="swiper-pagination"></div>
|
||||||
if (file_exists($next_arrow_icon)) {
|
|
||||||
echo file_get_contents($next_arrow_icon);
|
<div class="swiper-controls">
|
||||||
}
|
<div class="swiper-button-prev">
|
||||||
?>
|
<?php
|
||||||
|
$previous_arrow_icon = get_template_directory() . '/resources/img/elements/carhop-slider-previous.svg';
|
||||||
|
if (file_exists($previous_arrow_icon)) {
|
||||||
|
echo file_get_contents($previous_arrow_icon);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="swiper-button-next">
|
||||||
|
<?php
|
||||||
|
$next_arrow_icon = get_template_directory() . '/resources/img/elements/carhop-slider-next.svg';
|
||||||
|
if (file_exists($next_arrow_icon)) {
|
||||||
|
echo file_get_contents($next_arrow_icon);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user