changing block to auto-pull page cover illustration instead of icon

This commit is contained in:
Antoine M 2023-11-29 15:08:53 +01:00
parent 99b5273e5e
commit 66c950530b
6 changed files with 24 additions and 21 deletions

View File

@ -1 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '55aaaaa96d363ec8c816');
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '9816905fa59c35015482');

View File

@ -54,13 +54,14 @@ function Edit({
} = select("core/editor");
return getEditedPostAttribute("title");
});
const pageIcon = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => {
const pageIllustration = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => {
const currentPost = select("core/editor").getCurrentPost();
if (currentPost && currentPost.acf && currentPost.acf.page_icon) {
let Image = select("core").getMedia(currentPost.acf.page_icon);
if (currentPost && currentPost.acf && currentPost.acf.page_illustration) {
let Image = select("core").getMedia(currentPost.acf.page_illustration);
return Image;
}
});
console.log("pageIllustration", pageIllustration);
function onChangeBlockCustomTitle(blockCustomTitle) {
setAttributes({
blockCustomTitle
@ -152,7 +153,7 @@ function Edit({
label: "Couverture automatique",
checked: !hasCustomImage,
onChange: onChangeHasCustomImage
}), !hasCustomImage && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__.Tip, null, "La couverture est automatiquement g\xE9n\xE9r\xE9 \xE0 partir de l'icone de la page"), hasCustomImage && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, imageUrl && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("img", {
}), !hasCustomImage && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__.Tip, null, "La couverture est automatiquement g\xE9n\xE9r\xE9 \xE0 partir de l'illustration de couverture de la page."), hasCustomImage && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, imageUrl && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("img", {
src: imageUrl,
alt: imageAlt
}), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
@ -222,9 +223,9 @@ function Edit({
allowedBlocks: ["core/paragraph", "core/list", "core/button", "core/buttons", "gravityforms/form", "homegrade-content-blocks/section-titling"]
}), cta && cta.title && cta.url && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", {
href: cta.url
}, cta.title)), pageIcon && !hasCustomImage && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("img", {
}, cta.title)), pageIllustration && !hasCustomImage && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("img", {
className: "block-content-page-header__page-icon",
src: pageIcon.source_url,
src: pageIllustration.source_url,
alt: ""
}), hasCustomImage && imageUrl && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("img", {
src: imageUrl,

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
$pageHeaderTitle = $attributes['pageHeaderTitle'] ?? null;
$pageHeaderDescription = $attributes['pageHeaderDescription'] ?? null;
$cta = $attributes['cta'] ?? null;
$pageIcon = get_field('page_icon');
$pageIllustration = get_field('page_illustration');
$hasCustomImage = $attributes['hasCustomImage'] ?? null;
$customImageUrl = $attributes['imageUrl'] ?? null;
@ -31,8 +31,8 @@ $customTitle = $attributes['blockCustomTitle'] ?? null;
<?php endif; ?>
</div>
<?php if ($pageIcon && !$hasCustomImage) : ?>
<img class="block-content-page-header__page-icon" src="<?php echo $pageIcon['url'] ?>" alt="">
<?php if ($pageIllustration && !$hasCustomImage) : ?>
<img class="block-content-page-header__page-icon" src="<?php echo $pageIllustration['url'] ?>" alt="">
<?php endif; ?>
<?php if ($hasCustomImage && $customImageUrl) : ?>
<img class="block-content-page-header__page-icon" src="<?php echo $customImageUrl ?>" alt="<?php echo $customImageAlt ?>">

View File

@ -41,14 +41,16 @@ export default function Edit({ attributes, setAttributes }) {
return getEditedPostAttribute("title");
});
const pageIcon = useSelect((select) => {
const pageIllustration = useSelect((select) => {
const currentPost = select("core/editor").getCurrentPost();
if (currentPost && currentPost.acf && currentPost.acf.page_icon) {
let Image = select("core").getMedia(currentPost.acf.page_icon);
if (currentPost && currentPost.acf && currentPost.acf.page_illustration) {
let Image = select("core").getMedia(currentPost.acf.page_illustration);
return Image;
}
});
console.log("pageIllustration", pageIllustration);
function onChangeBlockCustomTitle(blockCustomTitle) {
setAttributes({ blockCustomTitle });
}
@ -139,8 +141,8 @@ export default function Edit({ attributes, setAttributes }) {
/>
{!hasCustomImage && (
<Tip>
La couverture est automatiquement généré à partir de l'icone de la
page
La couverture est automatiquement généré à partir de
l'illustration de couverture de la page.
</Tip>
)}
{hasCustomImage && (
@ -265,10 +267,10 @@ export default function Edit({ attributes, setAttributes }) {
/>
{cta && cta.title && cta.url && <a href={cta.url}>{cta.title}</a>}
</div>
{pageIcon && !hasCustomImage && (
{pageIllustration && !hasCustomImage && (
<img
className="block-content-page-header__page-icon"
src={pageIcon.source_url}
src={pageIllustration.source_url}
alt=""
/>
)}

View File

@ -2,7 +2,7 @@
$pageHeaderTitle = $attributes['pageHeaderTitle'] ?? null;
$pageHeaderDescription = $attributes['pageHeaderDescription'] ?? null;
$cta = $attributes['cta'] ?? null;
$pageIcon = get_field('page_icon');
$pageIllustration = get_field('page_illustration');
$hasCustomImage = $attributes['hasCustomImage'] ?? null;
$customImageUrl = $attributes['imageUrl'] ?? null;
@ -31,8 +31,8 @@ $customTitle = $attributes['blockCustomTitle'] ?? null;
<?php endif; ?>
</div>
<?php if ($pageIcon && !$hasCustomImage) : ?>
<img class="block-content-page-header__page-icon" src="<?php echo $pageIcon['url'] ?>" alt="">
<?php if ($pageIllustration && !$hasCustomImage) : ?>
<img class="block-content-page-header__page-icon" src="<?php echo $pageIllustration['url'] ?>" alt="">
<?php endif; ?>
<?php if ($hasCustomImage && $customImageUrl) : ?>
<img class="block-content-page-header__page-icon" src="<?php echo $customImageUrl ?>" alt="<?php echo $customImageAlt ?>">