handling free post description
This commit is contained in:
parent
6e36cf485e
commit
23d927e0b7
|
|
@ -22,6 +22,13 @@
|
|||
"postType": {
|
||||
"type": "string",
|
||||
"default": "conseils"
|
||||
},
|
||||
"hasDescription": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"postDescription": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '831260fc67b39b194bb9');
|
||||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '354aaf4f576100a5c65a');
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ __webpack_require__.r(__webpack_exports__);
|
|||
function OptionsSelectControl({
|
||||
setAttributes,
|
||||
relatedPostId,
|
||||
postDescription,
|
||||
hasDescription,
|
||||
postType
|
||||
}) {
|
||||
if (!postType || !setAttributes) return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, "Loading");
|
||||
|
|
@ -70,6 +72,11 @@ function OptionsSelectControl({
|
|||
}
|
||||
return c_value;
|
||||
}
|
||||
function handleHasDescriptionChange(hasDescription) {
|
||||
setAttributes({
|
||||
hasDescription
|
||||
});
|
||||
}
|
||||
function handleRelatedPostChange(postId) {
|
||||
setAttributes({
|
||||
relatedPostId: Number(postId)
|
||||
|
|
@ -133,10 +140,18 @@ function OptionsSelectControl({
|
|||
value: relatedPostId,
|
||||
options: postOptions,
|
||||
onChange: e => handleRelatedPostChange(e)
|
||||
}), relatedPostId && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Tip, null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Pour modifier le contenu de la question affichée ici, rendez-vous dans la fiche question correspondante.", "homegrade-blocks")), relatedPostId && editUrl && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", {
|
||||
}), relatedPostId && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Tip, null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Pourrrrrr modifier le contenu de la question affichée ici, rendez-vous dans la fiche question correspondante.", "homegrade-blocks")), relatedPostId && editUrl && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", {
|
||||
href: editUrl,
|
||||
className: "edit-question-button"
|
||||
}, "\xC9diter le post")));
|
||||
}, "\xC9diter le post")), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.PanelBody, {
|
||||
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Texte descriptif", "homegrade-blocks"),
|
||||
initialOpen: false
|
||||
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.CheckboxControl, {
|
||||
label: "Texte descriptif",
|
||||
help: "\xC0 cocher pour afficher un texte descriptif libre",
|
||||
checked: hasDescription,
|
||||
onChange: handleHasDescriptionChange
|
||||
})));
|
||||
}
|
||||
|
||||
/***/ }),
|
||||
|
|
@ -160,13 +175,11 @@ __webpack_require__.r(__webpack_exports__);
|
|||
/* 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__);
|
||||
/* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./editor.scss */ "./src/editor.scss");
|
||||
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
|
||||
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_5__);
|
||||
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/html-entities */ "@wordpress/html-entities");
|
||||
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_6__);
|
||||
/* harmony import */ var _OptionsSelectControl__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./OptionsSelectControl */ "./src/OptionsSelectControl.js");
|
||||
/* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @wordpress/core-data */ "@wordpress/core-data");
|
||||
/* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_8__);
|
||||
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/html-entities */ "@wordpress/html-entities");
|
||||
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_5__);
|
||||
/* harmony import */ var _OptionsSelectControl__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./OptionsSelectControl */ "./src/OptionsSelectControl.js");
|
||||
/* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/core-data */ "@wordpress/core-data");
|
||||
/* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_7__);
|
||||
|
||||
|
||||
|
||||
|
|
@ -176,14 +189,15 @@ __webpack_require__.r(__webpack_exports__);
|
|||
|
||||
|
||||
|
||||
|
||||
function Edit({
|
||||
attributes,
|
||||
setAttributes
|
||||
}) {
|
||||
const {
|
||||
relatedPostId,
|
||||
postType
|
||||
postType,
|
||||
hasDescription,
|
||||
postDescription
|
||||
} = attributes;
|
||||
const currentRelatedPost = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => relatedPostId && postType ? select("core").getEntityRecord("postType", postType, relatedPostId) : null, [relatedPostId, postType]);
|
||||
const post = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => select("core").getEntityRecord("postType", postType, relatedPostId));
|
||||
|
|
@ -204,9 +218,16 @@ function Edit({
|
|||
return (_media$source_url = media?.source_url) !== null && _media$source_url !== void 0 ? _media$source_url : null;
|
||||
}, [postParentTaxonomy]);
|
||||
const postTypeDatas = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => select("core").getEntityConfig("postType", postType));
|
||||
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_OptionsSelectControl__WEBPACK_IMPORTED_MODULE_7__["default"], {
|
||||
function handlePostDescriptionChange(description) {
|
||||
setAttributes({
|
||||
postDescription: description
|
||||
});
|
||||
}
|
||||
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_OptionsSelectControl__WEBPACK_IMPORTED_MODULE_6__["default"], {
|
||||
relatedPostId: relatedPostId,
|
||||
postType: postType,
|
||||
hasDescription: hasDescription,
|
||||
postDescription: postDescription,
|
||||
setAttributes: setAttributes
|
||||
}), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
||||
...(0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.useBlockProps)({
|
||||
|
|
@ -226,7 +247,12 @@ function Edit({
|
|||
class: "tag post-type-tag"
|
||||
}, postTypeDatas.label)), currentRelatedPost && currentRelatedPost.title && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("h2", {
|
||||
class: "post-card__title"
|
||||
}, (0,_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_6__.decodeEntities)(currentRelatedPost.title.rendered))), !relatedPostId && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Ce bloc n'est relié à aucun post. Rattachez-le à un post dans la barre latérale.", "homegrade-blocks__texte-backoffice")))));
|
||||
}, (0,_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_5__.decodeEntities)(currentRelatedPost.title.rendered)), hasDescription && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.RichText, {
|
||||
tagName: "p",
|
||||
onChange: handlePostDescriptionChange // Store updated content as a block attribute
|
||||
,
|
||||
placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Heading...") // Insérez votre description
|
||||
})), !relatedPostId && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Ce bloc n'est relié à aucun post. Rattachez-le à un post dans la barre latérale.", "homegrade-blocks__texte-backoffice")))));
|
||||
}
|
||||
|
||||
/***/ }),
|
||||
|
|
@ -388,7 +414,7 @@ module.exports = window["wp"]["i18n"];
|
|||
\************************/
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"homegrade-content-blocks/post-card","version":"0.1.0","title":"Post Link","category":"homegrade-blocks","description":"Pour afficher le lien vers un post (conseil, fiche-info, …) dans une carte","supports":{"anchor":true,"html":false},"textdomain":"homegrade-theme__bloks-texte-fonctionnel","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","render":"file:./render.php","attributes":{"relatedPostId":{"type":"number"},"postType":{"type":"string","default":"conseils"}}}');
|
||||
module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"homegrade-content-blocks/post-card","version":"0.1.0","title":"Post Link","category":"homegrade-blocks","description":"Pour afficher le lien vers un post (conseil, fiche-info, …) dans une carte","supports":{"anchor":true,"html":false},"textdomain":"homegrade-theme__bloks-texte-fonctionnel","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","render":"file:./render.php","attributes":{"relatedPostId":{"type":"number"},"postType":{"type":"string","default":"conseils"},"hasDescription":{"type":"boolean","default":false},"postDescription":{"type":"string"}}}');
|
||||
|
||||
/***/ })
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,4 @@
|
|||
<?php
|
||||
|
||||
|
||||
$relatedPostId = $attributes['relatedPostId'] ?? null;
|
||||
$postType = get_post_type_object(get_post_type($relatedPostId));
|
||||
|
||||
|
|
@ -14,11 +12,12 @@ $mainThematique = getMainThematique($thematique);
|
|||
$thematiqueColorSlug = $mainThematique->slug;
|
||||
$thematique_icon = get_field('taxonomy_pictures', 'thematiques' . '_' . $mainThematique->term_id)['icon'];
|
||||
|
||||
$postDescription = $attributes['postDescription'];
|
||||
|
||||
$coverUrl = $postType->name === 'videos-webinaires' && $postThumbnail ? $postThumbnail : ($thematique_icon ? $thematique_icon['url'] : null);
|
||||
|
||||
?>
|
||||
<a class="post-card" href="<?php echo $relatedPostUrl ?>" target="<?php echo $target ?>">
|
||||
<a class="post-card" href="<?php echo $relatedPostUrl ?>">
|
||||
|
||||
<img class="post-card__cover post-card__cover--<?php echo $postType->name ?>" src="<?php echo $coverUrl ?>" alt="">
|
||||
|
||||
|
|
@ -30,5 +29,9 @@ $coverUrl = $postType->name === 'videos-webinaires' && $postThumbnail ? $postTh
|
|||
<div class="tag post-type-tag"><?php echo $postType->label ?></div>
|
||||
</div>
|
||||
<h2 class="post-card__title"><?php echo $relatedPost->post_title ?></h2>
|
||||
<?php if ($postDescription): ?>
|
||||
<p><?php echo $postDescription ?></p>
|
||||
<?php endif; ?>
|
||||
<p></p>
|
||||
</div>
|
||||
</a>
|
||||
|
|
@ -6,7 +6,7 @@ import {
|
|||
ComboboxControl,
|
||||
} from "@wordpress/components";
|
||||
import "./editor.scss";
|
||||
import { Tip } from "@wordpress/components";
|
||||
import { Tip, CheckboxControl } from "@wordpress/components";
|
||||
|
||||
import { useSelect } from "@wordpress/data";
|
||||
import { useEffect, useState } from "@wordpress/element";
|
||||
|
|
@ -15,6 +15,8 @@ import { decodeEntities } from "@wordpress/html-entities";
|
|||
export default function OptionsSelectControl({
|
||||
setAttributes,
|
||||
relatedPostId,
|
||||
postDescription,
|
||||
hasDescription,
|
||||
postType,
|
||||
}) {
|
||||
if (!postType || !setAttributes) return <p>Loading</p>;
|
||||
|
|
@ -54,6 +56,10 @@ export default function OptionsSelectControl({
|
|||
return c_value;
|
||||
}
|
||||
|
||||
function handleHasDescriptionChange(hasDescription) {
|
||||
setAttributes({ hasDescription });
|
||||
}
|
||||
|
||||
function handleRelatedPostChange(postId) {
|
||||
setAttributes({ relatedPostId: Number(postId) });
|
||||
}
|
||||
|
|
@ -112,7 +118,7 @@ export default function OptionsSelectControl({
|
|||
{relatedPostId && (
|
||||
<Tip>
|
||||
{__(
|
||||
"Pour modifier le contenu de la question affichée ici, rendez-vous dans la fiche question correspondante.",
|
||||
"Pourrrrrr modifier le contenu de la question affichée ici, rendez-vous dans la fiche question correspondante.",
|
||||
"homegrade-blocks",
|
||||
)}
|
||||
</Tip>
|
||||
|
|
@ -123,6 +129,17 @@ export default function OptionsSelectControl({
|
|||
</a>
|
||||
)}
|
||||
</PanelBody>
|
||||
<PanelBody
|
||||
title={__("Texte descriptif", "homegrade-blocks")}
|
||||
initialOpen={false}
|
||||
>
|
||||
<CheckboxControl
|
||||
label="Texte descriptif"
|
||||
help="À cocher pour afficher un texte descriptif libre"
|
||||
checked={hasDescription}
|
||||
onChange={handleHasDescriptionChange}
|
||||
/>
|
||||
</PanelBody>
|
||||
</InspectorControls>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@
|
|||
"postType": {
|
||||
"type": "string",
|
||||
"default": "conseils"
|
||||
},
|
||||
"hasDescription": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"postDescription": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,15 +3,15 @@ import { useBlockProps } from "@wordpress/block-editor";
|
|||
|
||||
import { useSelect } from "@wordpress/data"; // pour les querry
|
||||
import "./editor.scss";
|
||||
import { RawHTML } from "@wordpress/element";
|
||||
import { useEffect } from "@wordpress/element";
|
||||
import { decodeEntities } from "@wordpress/html-entities";
|
||||
import OptionsSelectControl from "./OptionsSelectControl";
|
||||
import { RichText } from "@wordpress/block-editor";
|
||||
|
||||
import { useEntityProp } from "@wordpress/core-data";
|
||||
|
||||
export default function Edit({ attributes, setAttributes }) {
|
||||
const { relatedPostId, postType } = attributes;
|
||||
const { relatedPostId, postType, hasDescription, postDescription } =
|
||||
attributes;
|
||||
|
||||
const currentRelatedPost = useSelect(
|
||||
(select) =>
|
||||
|
|
@ -61,12 +61,17 @@ export default function Edit({ attributes, setAttributes }) {
|
|||
const postTypeDatas = useSelect((select) =>
|
||||
select("core").getEntityConfig("postType", postType),
|
||||
);
|
||||
function handlePostDescriptionChange(description) {
|
||||
setAttributes({ postDescription: description });
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<OptionsSelectControl
|
||||
relatedPostId={relatedPostId}
|
||||
postType={postType}
|
||||
hasDescription={hasDescription}
|
||||
postDescription={postDescription}
|
||||
setAttributes={setAttributes}
|
||||
/>
|
||||
|
||||
|
|
@ -75,7 +80,6 @@ export default function Edit({ attributes, setAttributes }) {
|
|||
className: `post-card`,
|
||||
})}
|
||||
>
|
||||
{/* postParentTaxonomy */}
|
||||
<img class="post-card__cover" alt="" src={thematiqueCoverUrl} />
|
||||
<div class="post-card__details">
|
||||
<div class="post-card__tags">
|
||||
|
|
@ -98,6 +102,13 @@ export default function Edit({ attributes, setAttributes }) {
|
|||
{decodeEntities(currentRelatedPost.title.rendered)}
|
||||
</h2>
|
||||
)}
|
||||
{hasDescription && (
|
||||
<RichText
|
||||
tagName="p"
|
||||
onChange={handlePostDescriptionChange} // Store updated content as a block attribute
|
||||
placeholder={__("Heading...")} // Insérez votre description
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{!relatedPostId && (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ $mainThematique = getMainThematique($thematique);
|
|||
$thematiqueColorSlug = $mainThematique->slug;
|
||||
$thematique_icon = get_field('taxonomy_pictures', 'thematiques' . '_' . $mainThematique->term_id)['icon'];
|
||||
|
||||
$postDescription = $attributes['postDescription'];
|
||||
|
||||
$coverUrl = $postType->name === 'videos-webinaires' && $postThumbnail ? $postThumbnail : ($thematique_icon ? $thematique_icon['url'] : null);
|
||||
|
||||
|
|
@ -28,5 +29,9 @@ $coverUrl = $postType->name === 'videos-webinaires' && $postThumbnail ? $postTh
|
|||
<div class="tag post-type-tag"><?php echo $postType->label ?></div>
|
||||
</div>
|
||||
<h2 class="post-card__title"><?php echo $relatedPost->post_title ?></h2>
|
||||
<?php if ($postDescription): ?>
|
||||
<p><?php echo $postDescription ?></p>
|
||||
<?php endif; ?>
|
||||
<p></p>
|
||||
</div>
|
||||
</a>
|
||||
Loading…
Reference in New Issue
Block a user