handling block depreacation
This commit is contained in:
parent
5582eef274
commit
5d8b790ac5
|
|
@ -21,9 +21,6 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"blockCustomTitle": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"pageHeaderTitle": {
|
"pageHeaderTitle": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'c79b0c0a1da145209afe');
|
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '33d8b36cf2904cb62a91');
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,112 @@
|
||||||
/******/ "use strict";
|
/******/ "use strict";
|
||||||
/******/ var __webpack_modules__ = ({
|
/******/ var __webpack_modules__ = ({
|
||||||
|
|
||||||
|
/***/ "./src/deprecated.js":
|
||||||
|
/*!***************************!*\
|
||||||
|
!*** ./src/deprecated.js ***!
|
||||||
|
\***************************/
|
||||||
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||||
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
||||||
|
/* harmony export */ });
|
||||||
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
||||||
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
||||||
|
/* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks");
|
||||||
|
/* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_1__);
|
||||||
|
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor");
|
||||||
|
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__);
|
||||||
|
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
|
||||||
|
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const v1 = {
|
||||||
|
attributes: {
|
||||||
|
hasCustomTitle: {
|
||||||
|
type: "boolean",
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
blockCustomTitle: {
|
||||||
|
type: "string"
|
||||||
|
},
|
||||||
|
pageHeaderTitle: {
|
||||||
|
type: "string"
|
||||||
|
},
|
||||||
|
hasCta: {
|
||||||
|
type: "boolean",
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
cta: {
|
||||||
|
type: "object"
|
||||||
|
},
|
||||||
|
hasCustomImage: {
|
||||||
|
type: "boolean",
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
imageUrl: {
|
||||||
|
type: "string"
|
||||||
|
},
|
||||||
|
imageAlt: {
|
||||||
|
type: "string"
|
||||||
|
},
|
||||||
|
imageId: {
|
||||||
|
type: "number"
|
||||||
|
},
|
||||||
|
imageProportion: {
|
||||||
|
type: "string",
|
||||||
|
default: "original"
|
||||||
|
},
|
||||||
|
anchor: {
|
||||||
|
type: "string"
|
||||||
|
},
|
||||||
|
coverSize: {
|
||||||
|
type: "string",
|
||||||
|
default: "medium"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
save({
|
||||||
|
attributes
|
||||||
|
}) {
|
||||||
|
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
||||||
|
..._wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.useBlockProps.save({
|
||||||
|
className: `innerblocks`
|
||||||
|
})
|
||||||
|
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.InnerBlocks.Content, null));
|
||||||
|
},
|
||||||
|
migrate(attributes, innerBlocks) {
|
||||||
|
const {
|
||||||
|
blockCustomTitle,
|
||||||
|
pageHeaderTitle,
|
||||||
|
...restAttributes
|
||||||
|
} = attributes;
|
||||||
|
|
||||||
|
// const pageTitle = useSelect((select) => {
|
||||||
|
// const { getEditedPostAttribute } = select("core/editor");
|
||||||
|
// return getEditedPostAttribute("title");
|
||||||
|
// });
|
||||||
|
|
||||||
|
return [restAttributes, [(0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_1__.createBlock)("homegrade-content-blocks/section-titling", {
|
||||||
|
content: attributes.sectionTitle,
|
||||||
|
level: 3
|
||||||
|
}, [(0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_1__.createBlock)("core/heading", {
|
||||||
|
placeholder: "Titre de section",
|
||||||
|
content: attributes.hasCustomTitle ? blockCustomTitle : "",
|
||||||
|
level: 1,
|
||||||
|
className: "section_titling__title"
|
||||||
|
}), (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_1__.createBlock)("core/paragraph", {
|
||||||
|
content: attributes.pageHeaderTitle,
|
||||||
|
placeholder: "Tapez votre sous-titre...",
|
||||||
|
className: "section_titling__subtitle"
|
||||||
|
})]), ...innerBlocks]];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ([v1]);
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
/***/ "./src/edit.js":
|
/***/ "./src/edit.js":
|
||||||
/*!*********************!*\
|
/*!*********************!*\
|
||||||
!*** ./src/edit.js ***!
|
!*** ./src/edit.js ***!
|
||||||
|
|
@ -36,10 +142,7 @@ function Edit({
|
||||||
setAttributes
|
setAttributes
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
anchor,
|
|
||||||
blockCustomTitle,
|
|
||||||
hasCustomTitle,
|
hasCustomTitle,
|
||||||
pageHeaderTitle,
|
|
||||||
hasCta,
|
hasCta,
|
||||||
cta,
|
cta,
|
||||||
hasCustomImage,
|
hasCustomImage,
|
||||||
|
|
@ -48,12 +151,6 @@ function Edit({
|
||||||
imageUrl,
|
imageUrl,
|
||||||
coverSize
|
coverSize
|
||||||
} = attributes;
|
} = attributes;
|
||||||
const pageTitle = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => {
|
|
||||||
const {
|
|
||||||
getEditedPostAttribute
|
|
||||||
} = select("core/editor");
|
|
||||||
return getEditedPostAttribute("title");
|
|
||||||
});
|
|
||||||
const pageIllustration = (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();
|
const currentPost = select("core/editor").getCurrentPost();
|
||||||
if (currentPost && currentPost.acf && currentPost.acf.page_illustration) {
|
if (currentPost && currentPost.acf && currentPost.acf.page_illustration) {
|
||||||
|
|
@ -61,16 +158,6 @@ function Edit({
|
||||||
return Image;
|
return Image;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function onChangeBlockCustomTitle(blockCustomTitle) {
|
|
||||||
setAttributes({
|
|
||||||
blockCustomTitle
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function onChangeTitle(newTitle) {
|
|
||||||
setAttributes({
|
|
||||||
pageHeaderTitle: newTitle
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function onChangeHasCustomTitle(newHasAutoTitle) {
|
function onChangeHasCustomTitle(newHasAutoTitle) {
|
||||||
setAttributes({
|
setAttributes({
|
||||||
hasCustomTitle: !hasCustomTitle
|
hasCustomTitle: !hasCustomTitle
|
||||||
|
|
@ -206,25 +293,10 @@ function Edit({
|
||||||
})
|
})
|
||||||
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
||||||
class: "block-content-page-header__content"
|
class: "block-content-page-header__content"
|
||||||
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.InnerBlocks, {
|
||||||
className: "section_titling section_titling--left"
|
template: [["homegrade-content-blocks/section-titling", {
|
||||||
}, !hasCustomTitle && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("h1", {
|
lock: true
|
||||||
className: "section_titling__title"
|
}], ["core/paragraph", {
|
||||||
}, pageTitle), hasCustomTitle && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.RichText, {
|
|
||||||
className: "section_titling__title",
|
|
||||||
tagName: "h1",
|
|
||||||
placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Ajouter ici le Titre du Bloc Header", "homegrade"),
|
|
||||||
value: blockCustomTitle,
|
|
||||||
onChange: onChangeBlockCustomTitle
|
|
||||||
}), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.RichText, {
|
|
||||||
className: "section_titling__subtitle",
|
|
||||||
tagName: "h2",
|
|
||||||
placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Ajouter ici le Titre du Bloc Header", "homegrade"),
|
|
||||||
value: pageHeaderTitle,
|
|
||||||
onChange: onChangeTitle
|
|
||||||
// style={{ textAlign: props.attributes.alignment }}
|
|
||||||
})), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.InnerBlocks, {
|
|
||||||
template: [["core/paragraph", {
|
|
||||||
placeholder: "Ajouter ici le texte"
|
placeholder: "Ajouter ici le texte"
|
||||||
}]],
|
}]],
|
||||||
allowedBlocks: ["core/paragraph", "core/list", "core/button", "core/buttons", "gravityforms/form", "homegrade-content-blocks/section-titling"]
|
allowedBlocks: ["core/paragraph", "core/list", "core/button", "core/buttons", "gravityforms/form", "homegrade-content-blocks/section-titling"]
|
||||||
|
|
@ -264,6 +336,8 @@ __webpack_require__.r(__webpack_exports__);
|
||||||
/* harmony import */ var _save__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./save */ "./src/save.js");
|
/* harmony import */ var _save__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./save */ "./src/save.js");
|
||||||
/* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./edit */ "./src/edit.js");
|
/* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./edit */ "./src/edit.js");
|
||||||
/* harmony import */ var _block_json__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./block.json */ "./src/block.json");
|
/* harmony import */ var _block_json__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./block.json */ "./src/block.json");
|
||||||
|
/* harmony import */ var _deprecated__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./deprecated */ "./src/deprecated.js");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -287,7 +361,8 @@ __webpack_require__.r(__webpack_exports__);
|
||||||
})))
|
})))
|
||||||
},
|
},
|
||||||
edit: _edit__WEBPACK_IMPORTED_MODULE_4__["default"],
|
edit: _edit__WEBPACK_IMPORTED_MODULE_4__["default"],
|
||||||
save: _save__WEBPACK_IMPORTED_MODULE_3__["default"]
|
save: _save__WEBPACK_IMPORTED_MODULE_3__["default"],
|
||||||
|
deprecated: _deprecated__WEBPACK_IMPORTED_MODULE_6__["default"]
|
||||||
});
|
});
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
@ -315,11 +390,7 @@ function save({
|
||||||
attributes,
|
attributes,
|
||||||
setAttributes
|
setAttributes
|
||||||
}) {
|
}) {
|
||||||
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.InnerBlocks.Content, null));
|
||||||
..._wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.useBlockProps.save({
|
|
||||||
className: `innerblocks`
|
|
||||||
})
|
|
||||||
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.InnerBlocks.Content, null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
@ -465,7 +536,7 @@ module.exports = window["wp"]["primitives"];
|
||||||
\************************/
|
\************************/
|
||||||
/***/ ((module) => {
|
/***/ ((module) => {
|
||||||
|
|
||||||
module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"homegrade-content-blocks/content-page-header","version":"0.1.0","title":"Content page header","category":"homegrade-blocks","icon":"smiley","description":"Bloc bannière/header de contenu de premier niveau pour les pages de contenu","supports":{"html":false,"anchor":true},"textdomain":"homegrade-blocks","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","render":"file:./render.php","attributes":{"hasCustomTitle":{"type":"boolean","default":false},"blockCustomTitle":{"type":"string"},"pageHeaderTitle":{"type":"string"},"hasCta":{"type":"boolean","default":false},"cta":{"type":"object"},"hasCustomImage":{"type":"boolean","default":false},"imageUrl":{"type":"string"},"imageAlt":{"type":"string"},"imageId":{"type":"number"},"imageProportion":{"type":"string","default":"original"},"anchor":{"type":"string"},"coverSize":{"type":"string","default":"medium"}}}');
|
module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"homegrade-content-blocks/content-page-header","version":"0.1.0","title":"Content page header","category":"homegrade-blocks","icon":"smiley","description":"Bloc bannière/header de contenu de premier niveau pour les pages de contenu","supports":{"html":false,"anchor":true},"textdomain":"homegrade-blocks","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","render":"file:./render.php","attributes":{"hasCustomTitle":{"type":"boolean","default":false},"pageHeaderTitle":{"type":"string"},"hasCta":{"type":"boolean","default":false},"cta":{"type":"object"},"hasCustomImage":{"type":"boolean","default":false},"imageUrl":{"type":"string"},"imageAlt":{"type":"string"},"imageId":{"type":"number"},"imageProportion":{"type":"string","default":"original"},"anchor":{"type":"string"},"coverSize":{"type":"string","default":"medium"}}}');
|
||||||
|
|
||||||
/***/ })
|
/***/ })
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -13,19 +13,8 @@ $customTitle = $attributes['blockCustomTitle'] ?? null;
|
||||||
$anchor = isset($attributes['anchor']) ? esc_html($attributes['anchor']) : null;
|
$anchor = isset($attributes['anchor']) ? esc_html($attributes['anchor']) : null;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
<section id="<?php echo $anchor ?? "" ?>" <?php echo get_block_wrapper_attributes(['class' => 'block-content-page-header']) ?>>
|
<section id="<?php echo $anchor ?? "" ?>" <?php echo get_block_wrapper_attributes(['class' => 'block-content-page-header']) ?>>
|
||||||
<div class="block-content-page-header__content">
|
<div class="block-content-page-header__content">
|
||||||
<div className="section_titling">
|
|
||||||
<?php if (!$attributes['hasCustomTitle']) : ?>
|
|
||||||
<h1 class="section_titling__title"><?php echo get_the_title() ?></h1>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($attributes['hasCustomTitle'] && $customTitle) : ?>
|
|
||||||
<h1 class="section_titling__title"><?php echo $customTitle ?></h1>
|
|
||||||
<?php endif; ?>
|
|
||||||
<p class="section_titling__subtitle"><?php echo $pageHeaderTitle ?> </p>
|
|
||||||
</div>
|
|
||||||
<p><?php echo $pageHeaderDescription ?> </p>
|
|
||||||
<?php echo $content ?>
|
<?php echo $content ?>
|
||||||
<?php if ($cta && $cta['title'] && $cta['url']) : ?>
|
<?php if ($cta && $cta['title'] && $cta['url']) : ?>
|
||||||
<a class="block-content-page-header__cta-link" href="<?php echo $cta['url'] ?>"><?php echo $cta['title'] ?></a>
|
<a class="block-content-page-header__cta-link" href="<?php echo $cta['url'] ?>"><?php echo $cta['title'] ?></a>
|
||||||
|
|
@ -38,5 +27,4 @@ $anchor = isset($attributes['anchor']) ? esc_html($attributes['anchor']) : null;
|
||||||
<?php if ($hasCustomImage && $customImageUrl) : ?>
|
<?php if ($hasCustomImage && $customImageUrl) : ?>
|
||||||
<img class="block-content-page-header__page-icon <?php echo $coverSize ? "block-content-page-header__page-icon--" . $coverSize : "" ?>" src="<?php echo $customImageUrl ?>" alt="<?php echo $customImageAlt ?>">
|
<img class="block-content-page-header__page-icon <?php echo $coverSize ? "block-content-page-header__page-icon--" . $coverSize : "" ?>" src="<?php echo $customImageUrl ?>" alt="<?php echo $customImageAlt ?>">
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -1,11 +1,4 @@
|
||||||
/*!**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
|
/*!**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
|
||||||
!*** css ./node_modules/.pnpm/css-loader@6.10.0_webpack@5.90.3/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[4].use[1]!./node_modules/.pnpm/postcss-loader@6.2.1_postcss@8.4.35_webpack@5.90.3/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[4].use[2]!./node_modules/.pnpm/sass-loader@12.6.0_sass@1.71.1_webpack@5.90.3/node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[4].use[3]!./src/style.scss ***!
|
!*** css ./node_modules/.pnpm/css-loader@6.10.0_webpack@5.90.3/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[4].use[1]!./node_modules/.pnpm/postcss-loader@6.2.1_postcss@8.4.35_webpack@5.90.3/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[4].use[2]!./node_modules/.pnpm/sass-loader@12.6.0_sass@1.71.1_webpack@5.90.3/node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[4].use[3]!./src/style.scss ***!
|
||||||
\**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
|
\**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
|
||||||
.block-content-page-header p {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.block-content-page-header .innerblocks p {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*# sourceMappingURL=style-index.css.map*/
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
{"version":3,"file":"./style-index.css","mappings":";;;AAEC;EACC;AADF;AAGC;EACC;AADF,C","sources":["webpack://multiblocks/./src/style.scss"],"sourcesContent":["// Styled by the theme\r\n.block-content-page-header {\r\n\tp {\r\n\t\tdisplay: none;\r\n\t}\r\n\t.innerblocks p {\r\n\t\tdisplay: block;\r\n\t}\r\n}\r\n"],"names":[],"sourceRoot":""}
|
|
||||||
|
|
@ -21,9 +21,6 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"blockCustomTitle": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"pageHeaderTitle": {
|
"pageHeaderTitle": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
101
blocks/content-page-header/src/deprecated.js
Normal file
101
blocks/content-page-header/src/deprecated.js
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
import { createBlock } from "@wordpress/blocks";
|
||||||
|
import { useBlockProps, RichText, InnerBlocks } from "@wordpress/block-editor";
|
||||||
|
import { useSelect } from "@wordpress/data";
|
||||||
|
|
||||||
|
const v1 = {
|
||||||
|
attributes: {
|
||||||
|
hasCustomTitle: {
|
||||||
|
type: "boolean",
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
blockCustomTitle: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
pageHeaderTitle: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
hasCta: {
|
||||||
|
type: "boolean",
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
cta: {
|
||||||
|
type: "object",
|
||||||
|
},
|
||||||
|
hasCustomImage: {
|
||||||
|
type: "boolean",
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
imageUrl: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
imageAlt: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
imageId: {
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
imageProportion: {
|
||||||
|
type: "string",
|
||||||
|
default: "original",
|
||||||
|
},
|
||||||
|
anchor: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
coverSize: {
|
||||||
|
type: "string",
|
||||||
|
default: "medium",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
save({ attributes }) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
{...useBlockProps.save({
|
||||||
|
className: `innerblocks`,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<InnerBlocks.Content />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
migrate(attributes, innerBlocks) {
|
||||||
|
const { blockCustomTitle, pageHeaderTitle, ...restAttributes } = attributes;
|
||||||
|
|
||||||
|
// const pageTitle = useSelect((select) => {
|
||||||
|
// const { getEditedPostAttribute } = select("core/editor");
|
||||||
|
// return getEditedPostAttribute("title");
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
return [
|
||||||
|
restAttributes,
|
||||||
|
[
|
||||||
|
createBlock(
|
||||||
|
"homegrade-content-blocks/section-titling",
|
||||||
|
{
|
||||||
|
content: attributes.sectionTitle,
|
||||||
|
level: 3,
|
||||||
|
},
|
||||||
|
[
|
||||||
|
createBlock("core/heading", {
|
||||||
|
placeholder: "Titre de section",
|
||||||
|
content: attributes.hasCustomTitle ? blockCustomTitle : "",
|
||||||
|
level: 1,
|
||||||
|
className: "section_titling__title",
|
||||||
|
}),
|
||||||
|
createBlock("core/paragraph", {
|
||||||
|
content: attributes.pageHeaderTitle,
|
||||||
|
placeholder: "Tapez votre sous-titre...",
|
||||||
|
className: "section_titling__subtitle",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
...innerBlocks,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default [v1];
|
||||||
|
|
@ -21,14 +21,11 @@ import {
|
||||||
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
||||||
} from "@wordpress/components";
|
} from "@wordpress/components";
|
||||||
|
|
||||||
import { trash } from "@wordpress/icons";
|
import { lock, trash } from "@wordpress/icons";
|
||||||
|
|
||||||
export default function Edit({ attributes, setAttributes }) {
|
export default function Edit({ attributes, setAttributes }) {
|
||||||
const {
|
const {
|
||||||
anchor,
|
|
||||||
blockCustomTitle,
|
|
||||||
hasCustomTitle,
|
hasCustomTitle,
|
||||||
pageHeaderTitle,
|
|
||||||
hasCta,
|
hasCta,
|
||||||
cta,
|
cta,
|
||||||
hasCustomImage,
|
hasCustomImage,
|
||||||
|
|
@ -38,11 +35,6 @@ export default function Edit({ attributes, setAttributes }) {
|
||||||
coverSize,
|
coverSize,
|
||||||
} = attributes;
|
} = attributes;
|
||||||
|
|
||||||
const pageTitle = useSelect((select) => {
|
|
||||||
const { getEditedPostAttribute } = select("core/editor");
|
|
||||||
return getEditedPostAttribute("title");
|
|
||||||
});
|
|
||||||
|
|
||||||
const pageIllustration = useSelect((select) => {
|
const pageIllustration = useSelect((select) => {
|
||||||
const currentPost = select("core/editor").getCurrentPost();
|
const currentPost = select("core/editor").getCurrentPost();
|
||||||
if (currentPost && currentPost.acf && currentPost.acf.page_illustration) {
|
if (currentPost && currentPost.acf && currentPost.acf.page_illustration) {
|
||||||
|
|
@ -51,12 +43,6 @@ export default function Edit({ attributes, setAttributes }) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function onChangeBlockCustomTitle(blockCustomTitle) {
|
|
||||||
setAttributes({ blockCustomTitle });
|
|
||||||
}
|
|
||||||
function onChangeTitle(newTitle) {
|
|
||||||
setAttributes({ pageHeaderTitle: newTitle });
|
|
||||||
}
|
|
||||||
function onChangeHasCustomTitle(newHasAutoTitle) {
|
function onChangeHasCustomTitle(newHasAutoTitle) {
|
||||||
setAttributes({ hasCustomTitle: !hasCustomTitle });
|
setAttributes({ hasCustomTitle: !hasCustomTitle });
|
||||||
if (newHasAutoTitle) {
|
if (newHasAutoTitle) {
|
||||||
|
|
@ -158,7 +144,7 @@ export default function Edit({ attributes, setAttributes }) {
|
||||||
!imageUrl
|
!imageUrl
|
||||||
? __(
|
? __(
|
||||||
"Ajouter votre image manuellement",
|
"Ajouter votre image manuellement",
|
||||||
"homegrade-blocks"
|
"homegrade-blocks",
|
||||||
)
|
)
|
||||||
: __("Remplacer", "homegrade-blocks")
|
: __("Remplacer", "homegrade-blocks")
|
||||||
}
|
}
|
||||||
|
|
@ -223,38 +209,9 @@ export default function Edit({ attributes, setAttributes }) {
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div class="block-content-page-header__content">
|
<div class="block-content-page-header__content">
|
||||||
<div className="section_titling section_titling--left">
|
|
||||||
{!hasCustomTitle && (
|
|
||||||
<h1 className="section_titling__title">{pageTitle}</h1>
|
|
||||||
)}
|
|
||||||
{hasCustomTitle && (
|
|
||||||
<RichText
|
|
||||||
className="section_titling__title"
|
|
||||||
tagName="h1"
|
|
||||||
placeholder={__(
|
|
||||||
"Ajouter ici le Titre du Bloc Header",
|
|
||||||
"homegrade"
|
|
||||||
)}
|
|
||||||
value={blockCustomTitle}
|
|
||||||
onChange={onChangeBlockCustomTitle}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<RichText
|
|
||||||
className="section_titling__subtitle"
|
|
||||||
tagName="h2"
|
|
||||||
placeholder={__(
|
|
||||||
"Ajouter ici le Titre du Bloc Header",
|
|
||||||
"homegrade"
|
|
||||||
)}
|
|
||||||
value={pageHeaderTitle}
|
|
||||||
onChange={onChangeTitle}
|
|
||||||
// style={{ textAlign: props.attributes.alignment }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<InnerBlocks
|
<InnerBlocks
|
||||||
template={[
|
template={[
|
||||||
|
["homegrade-content-blocks/section-titling", { lock: true }],
|
||||||
["core/paragraph", { placeholder: "Ajouter ici le texte" }],
|
["core/paragraph", { placeholder: "Ajouter ici le texte" }],
|
||||||
]}
|
]}
|
||||||
allowedBlocks={[
|
allowedBlocks={[
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import "./style.scss";
|
||||||
import save from "./save";
|
import save from "./save";
|
||||||
import Edit from "./edit";
|
import Edit from "./edit";
|
||||||
import metadata from "./block.json";
|
import metadata from "./block.json";
|
||||||
|
import deprecated from "./deprecated";
|
||||||
|
|
||||||
registerBlockType(metadata.name, {
|
registerBlockType(metadata.name, {
|
||||||
icon: {
|
icon: {
|
||||||
|
|
@ -26,4 +27,5 @@ registerBlockType(metadata.name, {
|
||||||
},
|
},
|
||||||
edit: Edit,
|
edit: Edit,
|
||||||
save,
|
save,
|
||||||
|
deprecated
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -13,19 +13,8 @@ $customTitle = $attributes['blockCustomTitle'] ?? null;
|
||||||
$anchor = isset($attributes['anchor']) ? esc_html($attributes['anchor']) : null;
|
$anchor = isset($attributes['anchor']) ? esc_html($attributes['anchor']) : null;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
<section id="<?php echo $anchor ?? "" ?>" <?php echo get_block_wrapper_attributes(['class' => 'block-content-page-header']) ?>>
|
<section id="<?php echo $anchor ?? "" ?>" <?php echo get_block_wrapper_attributes(['class' => 'block-content-page-header']) ?>>
|
||||||
<div class="block-content-page-header__content">
|
<div class="block-content-page-header__content">
|
||||||
<div className="section_titling">
|
|
||||||
<?php if (!$attributes['hasCustomTitle']) : ?>
|
|
||||||
<h1 class="section_titling__title"><?php echo get_the_title() ?></h1>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php if ($attributes['hasCustomTitle'] && $customTitle) : ?>
|
|
||||||
<h1 class="section_titling__title"><?php echo $customTitle ?></h1>
|
|
||||||
<?php endif; ?>
|
|
||||||
<p class="section_titling__subtitle"><?php echo $pageHeaderTitle ?> </p>
|
|
||||||
</div>
|
|
||||||
<p><?php echo $pageHeaderDescription ?> </p>
|
|
||||||
<?php echo $content ?>
|
<?php echo $content ?>
|
||||||
<?php if ($cta && $cta['title'] && $cta['url']) : ?>
|
<?php if ($cta && $cta['title'] && $cta['url']) : ?>
|
||||||
<a class="block-content-page-header__cta-link" href="<?php echo $cta['url'] ?>"><?php echo $cta['title'] ?></a>
|
<a class="block-content-page-header__cta-link" href="<?php echo $cta['url'] ?>"><?php echo $cta['title'] ?></a>
|
||||||
|
|
@ -38,5 +27,4 @@ $anchor = isset($attributes['anchor']) ? esc_html($attributes['anchor']) : null;
|
||||||
<?php if ($hasCustomImage && $customImageUrl) : ?>
|
<?php if ($hasCustomImage && $customImageUrl) : ?>
|
||||||
<img class="block-content-page-header__page-icon <?php echo $coverSize ? "block-content-page-header__page-icon--" . $coverSize : "" ?>" src="<?php echo $customImageUrl ?>" alt="<?php echo $customImageAlt ?>">
|
<img class="block-content-page-header__page-icon <?php echo $coverSize ? "block-content-page-header__page-icon--" . $coverSize : "" ?>" src="<?php echo $customImageUrl ?>" alt="<?php echo $customImageAlt ?>">
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -3,12 +3,8 @@ import { __ } from "@wordpress/i18n";
|
||||||
|
|
||||||
export default function save({ attributes, setAttributes }) {
|
export default function save({ attributes, setAttributes }) {
|
||||||
return (
|
return (
|
||||||
<div
|
<>
|
||||||
{...useBlockProps.save({
|
|
||||||
className: `innerblocks`,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<InnerBlocks.Content />
|
<InnerBlocks.Content />
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
// Styled by the theme
|
// Styled by the theme
|
||||||
.block-content-page-header {
|
// .block-content-page-header {
|
||||||
p {
|
// p {
|
||||||
display: none;
|
// display: none;
|
||||||
}
|
// }
|
||||||
.innerblocks p {
|
// .innerblocks p {
|
||||||
display: block;
|
// display: block;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user