introducing component
This commit is contained in:
parent
19a369cdea
commit
051d70a80a
18
blocks/post-card/.editorconfig
Normal file
18
blocks/post-card/.editorconfig
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# This file is for unifying the coding style for different editors and IDEs
|
||||||
|
# editorconfig.org
|
||||||
|
|
||||||
|
# WordPress Coding Standards
|
||||||
|
# https://make.wordpress.org/core/handbook/coding-standards/
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
indent_style = tab
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
30
blocks/post-card/.gitignore
vendored
Normal file
30
blocks/post-card/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Output of `npm pack`
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Output of `wp-scripts plugin-zip`
|
||||||
|
*.zip
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
27
blocks/post-card/build/block.json
Normal file
27
blocks/post-card/build/block.json
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||||
|
"apiVersion": 2,
|
||||||
|
"name": "homegrade-content-blocks/post-card",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"title": "Post Card",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
blocks/post-card/build/index.asset.php
Normal file
1
blocks/post-card/build/index.asset.php
Normal file
|
|
@ -0,0 +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' => '8770e094166a8fa4365e');
|
||||||
14
blocks/post-card/build/index.css
Normal file
14
blocks/post-card/build/index.css
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
/*!***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
|
||||||
|
!*** 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/editor.scss ***!
|
||||||
|
\***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
|
||||||
|
/**
|
||||||
|
* The following styles get applied inside the editor only.
|
||||||
|
*
|
||||||
|
* Replace them with your own styles or remove the file completely.
|
||||||
|
*/
|
||||||
|
.post-content-container {
|
||||||
|
opacity: 50%;
|
||||||
|
filter: saturate(90%);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*# sourceMappingURL=index.css.map*/
|
||||||
1
blocks/post-card/build/index.css.map
Normal file
1
blocks/post-card/build/index.css.map
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"index.css","mappings":";;;AAAA;;;;EAAA;AAMA;EACC;EACA;AAAD,C","sources":["webpack://multiblocks/./src/editor.scss"],"sourcesContent":["/**\n * The following styles get applied inside the editor only.\n *\n * Replace them with your own styles or remove the file completely.\n */\n\n.post-content-container{\n\topacity: 50%;\n\tfilter: saturate(90%);\n}\n"],"names":[],"sourceRoot":""}
|
||||||
561
blocks/post-card/build/index.js
Normal file
561
blocks/post-card/build/index.js
Normal file
|
|
@ -0,0 +1,561 @@
|
||||||
|
/******/ (() => { // webpackBootstrap
|
||||||
|
/******/ "use strict";
|
||||||
|
/******/ var __webpack_modules__ = ({
|
||||||
|
|
||||||
|
/***/ "./src/OptionsSelectControl.js":
|
||||||
|
/*!*************************************!*\
|
||||||
|
!*** ./src/OptionsSelectControl.js ***!
|
||||||
|
\*************************************/
|
||||||
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||||
|
/* harmony export */ "default": () => (/* binding */ OptionsSelectControl)
|
||||||
|
/* 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_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
|
||||||
|
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__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_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
|
||||||
|
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__);
|
||||||
|
/* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./editor.scss */ "./src/editor.scss");
|
||||||
|
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
|
||||||
|
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_5__);
|
||||||
|
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
|
||||||
|
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_6__);
|
||||||
|
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/html-entities */ "@wordpress/html-entities");
|
||||||
|
/* harmony import */ var _wordpress_html_entities__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_7__);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function OptionsSelectControl({
|
||||||
|
setAttributes,
|
||||||
|
relatedPostId,
|
||||||
|
postType
|
||||||
|
}) {
|
||||||
|
if (!postType || !setAttributes) return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, "Loading");
|
||||||
|
let [postOptions, setPostOptions] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_6__.useState)(null);
|
||||||
|
const lang = getAdminLanguageFromCookie("wp-wpml_current_language");
|
||||||
|
const optionPages = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_5__.useSelect)(select => {
|
||||||
|
if (!postType) return null;
|
||||||
|
let query = {
|
||||||
|
status: "publish",
|
||||||
|
per_page: -1,
|
||||||
|
lang: lang
|
||||||
|
};
|
||||||
|
return select("core").getEntityRecords("postType", postType, query);
|
||||||
|
}, [postType, lang]);
|
||||||
|
const editUrl = relatedPostId ? `${window.location.origin}/wp-admin/post.php?post=${relatedPostId}&action=edit` : null;
|
||||||
|
function getAdminLanguageFromCookie(c_name) {
|
||||||
|
var c_value = document.cookie,
|
||||||
|
c_start = c_value.indexOf(" " + c_name + "=");
|
||||||
|
if (c_start == -1) c_start = c_value.indexOf(c_name + "=");
|
||||||
|
if (c_start == -1) {
|
||||||
|
c_value = null;
|
||||||
|
} else {
|
||||||
|
c_start = c_value.indexOf("=", c_start) + 1;
|
||||||
|
var c_end = c_value.indexOf(";", c_start);
|
||||||
|
if (c_end == -1) {
|
||||||
|
c_end = c_value.length;
|
||||||
|
}
|
||||||
|
c_value = unescape(c_value.substring(c_start, c_end));
|
||||||
|
}
|
||||||
|
return c_value;
|
||||||
|
}
|
||||||
|
function handleRelatedPostChange(postId) {
|
||||||
|
setAttributes({
|
||||||
|
relatedPostId: Number(postId)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function handlePostTypeChange(postType) {
|
||||||
|
setAttributes({
|
||||||
|
postType: postType,
|
||||||
|
relatedPostId: null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function buildSelectOptions(optionPages) {
|
||||||
|
let options = [];
|
||||||
|
if (optionPages && optionPages.length > 0) {
|
||||||
|
options.push({
|
||||||
|
value: 0,
|
||||||
|
label: "Selectionnez une page"
|
||||||
|
});
|
||||||
|
optionPages.forEach(page => {
|
||||||
|
options.push({
|
||||||
|
value: page.id,
|
||||||
|
label: (0,_wordpress_html_entities__WEBPACK_IMPORTED_MODULE_7__.decodeEntities)(page.title.rendered)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
options.push({
|
||||||
|
value: 0,
|
||||||
|
label: "Pas encore de questions..."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_6__.useEffect)(() => {
|
||||||
|
if (!optionPages || !postType) return;
|
||||||
|
if (optionPages && optionPages.length > 0) {
|
||||||
|
setPostOptions(buildSelectOptions(optionPages));
|
||||||
|
}
|
||||||
|
}, [optionPages, postType]);
|
||||||
|
let panelTitle = "Post Reliée";
|
||||||
|
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.InspectorControls, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.PanelBody, {
|
||||||
|
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Contenu Reliée", "homegrade-blocks")
|
||||||
|
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.SelectControl, {
|
||||||
|
label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Type de post", "homegrade-blocks"),
|
||||||
|
options: [{
|
||||||
|
value: "conseils",
|
||||||
|
label: "Conseils"
|
||||||
|
}, {
|
||||||
|
value: "fiches-infos",
|
||||||
|
label: "Fiches infos"
|
||||||
|
}, {
|
||||||
|
value: "questions",
|
||||||
|
label: "Questions"
|
||||||
|
}, {
|
||||||
|
value: "videos-webinaires",
|
||||||
|
label: "Videos / Webinaires"
|
||||||
|
}],
|
||||||
|
value: postType !== null && postType !== void 0 ? postType : null,
|
||||||
|
onChange: handlePostTypeChange
|
||||||
|
}), postOptions && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ComboboxControl, {
|
||||||
|
label: panelTitle,
|
||||||
|
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", {
|
||||||
|
href: editUrl,
|
||||||
|
className: "edit-question-button"
|
||||||
|
}, "\xC9diter le post")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./src/edit.js":
|
||||||
|
/*!*********************!*\
|
||||||
|
!*** ./src/edit.js ***!
|
||||||
|
\*********************/
|
||||||
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||||
|
/* harmony export */ "default": () => (/* binding */ Edit)
|
||||||
|
/* 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_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
|
||||||
|
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__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__);
|
||||||
|
/* 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__);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// pour les querry
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function Edit({
|
||||||
|
attributes,
|
||||||
|
setAttributes
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
relatedPostId,
|
||||||
|
postType
|
||||||
|
} = 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));
|
||||||
|
const postMainTaxonomy = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => {
|
||||||
|
var _post$thematiques;
|
||||||
|
return select("core").getEntityRecord("taxonomy", "thematiques", (_post$thematiques = post?.thematiques) !== null && _post$thematiques !== void 0 ? _post$thematiques : null);
|
||||||
|
}, [post]);
|
||||||
|
const postParentTaxonomy = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => {
|
||||||
|
var _postMainTaxonomy$par;
|
||||||
|
if (!postMainTaxonomy) return null;
|
||||||
|
if (postMainTaxonomy && !postMainTaxonomy.parent) return postMainTaxonomy;
|
||||||
|
return select("core").getEntityRecord("taxonomy", "thematiques", (_postMainTaxonomy$par = postMainTaxonomy?.parent) !== null && _postMainTaxonomy$par !== void 0 ? _postMainTaxonomy$par : null);
|
||||||
|
}, [postMainTaxonomy]);
|
||||||
|
const thematiqueCoverUrl = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => {
|
||||||
|
var _media$source_url;
|
||||||
|
let thematiqueMediaId = postParentTaxonomy?.acf?.taxonomy_pictures?.icon;
|
||||||
|
const media = select("core").getMedia(thematiqueMediaId);
|
||||||
|
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"], {
|
||||||
|
relatedPostId: relatedPostId,
|
||||||
|
postType: postType,
|
||||||
|
setAttributes: setAttributes
|
||||||
|
}), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
||||||
|
...(0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.useBlockProps)({
|
||||||
|
className: `post-card`
|
||||||
|
})
|
||||||
|
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("img", {
|
||||||
|
class: "post-card__cover",
|
||||||
|
alt: "",
|
||||||
|
src: thematiqueCoverUrl
|
||||||
|
}), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
||||||
|
class: "post-card__details"
|
||||||
|
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
||||||
|
class: "post-card__tags"
|
||||||
|
}, postParentTaxonomy && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
||||||
|
class: "tag thematique-tag thematique-tag--" + postParentTaxonomy.slug
|
||||||
|
}, postParentTaxonomy.name), postTypeDatas && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
|
||||||
|
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")))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./src/index.js":
|
||||||
|
/*!**********************!*\
|
||||||
|
!*** ./src/index.js ***!
|
||||||
|
\**********************/
|
||||||
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
/* 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 _style_scss__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./style.scss */ "./src/style.scss");
|
||||||
|
/* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./edit */ "./src/edit.js");
|
||||||
|
/* harmony import */ var _block_json__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./block.json */ "./src/block.json");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_1__.registerBlockType)(_block_json__WEBPACK_IMPORTED_MODULE_4__.name, {
|
||||||
|
icon: {
|
||||||
|
src: (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("svg", {
|
||||||
|
xmlns: "http://www.w3.org/2000/svg",
|
||||||
|
width: "62.01",
|
||||||
|
height: "58.04",
|
||||||
|
viewBox: "0 0 62.01 58.04"
|
||||||
|
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("g", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("path", {
|
||||||
|
class: "cls-1",
|
||||||
|
d: "M14.68,21.37c5.73-2.02,8.73-8.31,6.71-14.04C19.36,1.61,13.08-1.39,7.35.63,1.62,2.66-1.38,8.94.64,14.67c1.11,3.13,3.57,5.6,6.71,6.71l.67.24v14.82l-.68.23c-5.73,2.02-8.73,8.31-6.71,14.04,2.02,5.73,8.31,8.73,14.04,6.71,5.73-2.02,8.73-8.31,6.71-14.04-1.11-3.13-3.57-5.6-6.71-6.71l-.66-.23v-14.82l.67-.24ZM16.01,47.02c0,2.76-2.24,5-5,5s-5-2.24-5-5,2.24-5,5-5,5,2.24,5,5ZM11.01,16.02c-2.76,0-5-2.24-5-5s2.24-5,5-5,5,2.24,5,5-2.24,5-5,5ZM34.01,8.02h25c1.66,0,3-1.34,3-3s-1.34-3-3-3h-25c-1.66,0-3,1.34-3,3s1.34,3,3,3ZM59.01,18.02h-25c-1.66,0-3,1.34-3,3s1.34,3,3,3h25c1.66,0,3-1.34,3-3s-1.34-3-3-3ZM59.01,34.02h-25c-1.66,0-3,1.34-3,3s1.34,3,3,3h25c1.66,0,3-1.34,3-3s-1.34-3-3-3ZM59.01,50.02h-25c-1.66,0-3,1.34-3,3s1.34,3,3,3h25c1.66,0,3-1.34,3-3s-1.34-3-3-3Z"
|
||||||
|
}))),
|
||||||
|
foreground: "#DF1E1E"
|
||||||
|
},
|
||||||
|
edit: _edit__WEBPACK_IMPORTED_MODULE_3__["default"]
|
||||||
|
});
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./src/editor.scss":
|
||||||
|
/*!*************************!*\
|
||||||
|
!*** ./src/editor.scss ***!
|
||||||
|
\*************************/
|
||||||
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
// extracted by mini-css-extract-plugin
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./src/style.scss":
|
||||||
|
/*!************************!*\
|
||||||
|
!*** ./src/style.scss ***!
|
||||||
|
\************************/
|
||||||
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
// extracted by mini-css-extract-plugin
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "react":
|
||||||
|
/*!************************!*\
|
||||||
|
!*** external "React" ***!
|
||||||
|
\************************/
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
module.exports = window["React"];
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "@wordpress/block-editor":
|
||||||
|
/*!*************************************!*\
|
||||||
|
!*** external ["wp","blockEditor"] ***!
|
||||||
|
\*************************************/
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
module.exports = window["wp"]["blockEditor"];
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "@wordpress/blocks":
|
||||||
|
/*!********************************!*\
|
||||||
|
!*** external ["wp","blocks"] ***!
|
||||||
|
\********************************/
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
module.exports = window["wp"]["blocks"];
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "@wordpress/components":
|
||||||
|
/*!************************************!*\
|
||||||
|
!*** external ["wp","components"] ***!
|
||||||
|
\************************************/
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
module.exports = window["wp"]["components"];
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "@wordpress/core-data":
|
||||||
|
/*!**********************************!*\
|
||||||
|
!*** external ["wp","coreData"] ***!
|
||||||
|
\**********************************/
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
module.exports = window["wp"]["coreData"];
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "@wordpress/data":
|
||||||
|
/*!******************************!*\
|
||||||
|
!*** external ["wp","data"] ***!
|
||||||
|
\******************************/
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
module.exports = window["wp"]["data"];
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "@wordpress/element":
|
||||||
|
/*!*********************************!*\
|
||||||
|
!*** external ["wp","element"] ***!
|
||||||
|
\*********************************/
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
module.exports = window["wp"]["element"];
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "@wordpress/html-entities":
|
||||||
|
/*!**************************************!*\
|
||||||
|
!*** external ["wp","htmlEntities"] ***!
|
||||||
|
\**************************************/
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
module.exports = window["wp"]["htmlEntities"];
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "@wordpress/i18n":
|
||||||
|
/*!******************************!*\
|
||||||
|
!*** external ["wp","i18n"] ***!
|
||||||
|
\******************************/
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
module.exports = window["wp"]["i18n"];
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./src/block.json":
|
||||||
|
/*!************************!*\
|
||||||
|
!*** ./src/block.json ***!
|
||||||
|
\************************/
|
||||||
|
/***/ ((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 Card","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"}}}');
|
||||||
|
|
||||||
|
/***/ })
|
||||||
|
|
||||||
|
/******/ });
|
||||||
|
/************************************************************************/
|
||||||
|
/******/ // The module cache
|
||||||
|
/******/ var __webpack_module_cache__ = {};
|
||||||
|
/******/
|
||||||
|
/******/ // The require function
|
||||||
|
/******/ function __webpack_require__(moduleId) {
|
||||||
|
/******/ // Check if module is in cache
|
||||||
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||||
|
/******/ if (cachedModule !== undefined) {
|
||||||
|
/******/ return cachedModule.exports;
|
||||||
|
/******/ }
|
||||||
|
/******/ // Create a new module (and put it into the cache)
|
||||||
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||||
|
/******/ // no module.id needed
|
||||||
|
/******/ // no module.loaded needed
|
||||||
|
/******/ exports: {}
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // Execute the module function
|
||||||
|
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
||||||
|
/******/
|
||||||
|
/******/ // Return the exports of the module
|
||||||
|
/******/ return module.exports;
|
||||||
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/******/ // expose the modules object (__webpack_modules__)
|
||||||
|
/******/ __webpack_require__.m = __webpack_modules__;
|
||||||
|
/******/
|
||||||
|
/************************************************************************/
|
||||||
|
/******/ /* webpack/runtime/chunk loaded */
|
||||||
|
/******/ (() => {
|
||||||
|
/******/ var deferred = [];
|
||||||
|
/******/ __webpack_require__.O = (result, chunkIds, fn, priority) => {
|
||||||
|
/******/ if(chunkIds) {
|
||||||
|
/******/ priority = priority || 0;
|
||||||
|
/******/ for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];
|
||||||
|
/******/ deferred[i] = [chunkIds, fn, priority];
|
||||||
|
/******/ return;
|
||||||
|
/******/ }
|
||||||
|
/******/ var notFulfilled = Infinity;
|
||||||
|
/******/ for (var i = 0; i < deferred.length; i++) {
|
||||||
|
/******/ var [chunkIds, fn, priority] = deferred[i];
|
||||||
|
/******/ var fulfilled = true;
|
||||||
|
/******/ for (var j = 0; j < chunkIds.length; j++) {
|
||||||
|
/******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {
|
||||||
|
/******/ chunkIds.splice(j--, 1);
|
||||||
|
/******/ } else {
|
||||||
|
/******/ fulfilled = false;
|
||||||
|
/******/ if(priority < notFulfilled) notFulfilled = priority;
|
||||||
|
/******/ }
|
||||||
|
/******/ }
|
||||||
|
/******/ if(fulfilled) {
|
||||||
|
/******/ deferred.splice(i--, 1)
|
||||||
|
/******/ var r = fn();
|
||||||
|
/******/ if (r !== undefined) result = r;
|
||||||
|
/******/ }
|
||||||
|
/******/ }
|
||||||
|
/******/ return result;
|
||||||
|
/******/ };
|
||||||
|
/******/ })();
|
||||||
|
/******/
|
||||||
|
/******/ /* webpack/runtime/compat get default export */
|
||||||
|
/******/ (() => {
|
||||||
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||||
|
/******/ __webpack_require__.n = (module) => {
|
||||||
|
/******/ var getter = module && module.__esModule ?
|
||||||
|
/******/ () => (module['default']) :
|
||||||
|
/******/ () => (module);
|
||||||
|
/******/ __webpack_require__.d(getter, { a: getter });
|
||||||
|
/******/ return getter;
|
||||||
|
/******/ };
|
||||||
|
/******/ })();
|
||||||
|
/******/
|
||||||
|
/******/ /* webpack/runtime/define property getters */
|
||||||
|
/******/ (() => {
|
||||||
|
/******/ // define getter functions for harmony exports
|
||||||
|
/******/ __webpack_require__.d = (exports, definition) => {
|
||||||
|
/******/ for(var key in definition) {
|
||||||
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
||||||
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
||||||
|
/******/ }
|
||||||
|
/******/ }
|
||||||
|
/******/ };
|
||||||
|
/******/ })();
|
||||||
|
/******/
|
||||||
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
||||||
|
/******/ (() => {
|
||||||
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
||||||
|
/******/ })();
|
||||||
|
/******/
|
||||||
|
/******/ /* webpack/runtime/make namespace object */
|
||||||
|
/******/ (() => {
|
||||||
|
/******/ // define __esModule on exports
|
||||||
|
/******/ __webpack_require__.r = (exports) => {
|
||||||
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||||
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||||
|
/******/ }
|
||||||
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
/******/ };
|
||||||
|
/******/ })();
|
||||||
|
/******/
|
||||||
|
/******/ /* webpack/runtime/jsonp chunk loading */
|
||||||
|
/******/ (() => {
|
||||||
|
/******/ // no baseURI
|
||||||
|
/******/
|
||||||
|
/******/ // object to store loaded and loading chunks
|
||||||
|
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
|
||||||
|
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
|
||||||
|
/******/ var installedChunks = {
|
||||||
|
/******/ "index": 0,
|
||||||
|
/******/ "./style-index": 0
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // no chunk on demand loading
|
||||||
|
/******/
|
||||||
|
/******/ // no prefetching
|
||||||
|
/******/
|
||||||
|
/******/ // no preloaded
|
||||||
|
/******/
|
||||||
|
/******/ // no HMR
|
||||||
|
/******/
|
||||||
|
/******/ // no HMR manifest
|
||||||
|
/******/
|
||||||
|
/******/ __webpack_require__.O.j = (chunkId) => (installedChunks[chunkId] === 0);
|
||||||
|
/******/
|
||||||
|
/******/ // install a JSONP callback for chunk loading
|
||||||
|
/******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => {
|
||||||
|
/******/ var [chunkIds, moreModules, runtime] = data;
|
||||||
|
/******/ // add "moreModules" to the modules object,
|
||||||
|
/******/ // then flag all "chunkIds" as loaded and fire callback
|
||||||
|
/******/ var moduleId, chunkId, i = 0;
|
||||||
|
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
|
||||||
|
/******/ for(moduleId in moreModules) {
|
||||||
|
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
|
||||||
|
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
|
||||||
|
/******/ }
|
||||||
|
/******/ }
|
||||||
|
/******/ if(runtime) var result = runtime(__webpack_require__);
|
||||||
|
/******/ }
|
||||||
|
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
|
||||||
|
/******/ for(;i < chunkIds.length; i++) {
|
||||||
|
/******/ chunkId = chunkIds[i];
|
||||||
|
/******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
|
||||||
|
/******/ installedChunks[chunkId][0]();
|
||||||
|
/******/ }
|
||||||
|
/******/ installedChunks[chunkId] = 0;
|
||||||
|
/******/ }
|
||||||
|
/******/ return __webpack_require__.O(result);
|
||||||
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/******/ var chunkLoadingGlobal = globalThis["webpackChunkmultiblocks"] = globalThis["webpackChunkmultiblocks"] || [];
|
||||||
|
/******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
|
||||||
|
/******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
|
||||||
|
/******/ })();
|
||||||
|
/******/
|
||||||
|
/************************************************************************/
|
||||||
|
/******/
|
||||||
|
/******/ // startup
|
||||||
|
/******/ // Load entry module and return exports
|
||||||
|
/******/ // This entry module depends on other loaded chunks and execution need to be delayed
|
||||||
|
/******/ var __webpack_exports__ = __webpack_require__.O(undefined, ["./style-index"], () => (__webpack_require__("./src/index.js")))
|
||||||
|
/******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
|
||||||
|
/******/
|
||||||
|
/******/ })()
|
||||||
|
;
|
||||||
|
//# sourceMappingURL=index.js.map
|
||||||
1
blocks/post-card/build/index.js.map
Normal file
1
blocks/post-card/build/index.js.map
Normal file
File diff suppressed because one or more lines are too long
33
blocks/post-card/build/render.php
Normal file
33
blocks/post-card/build/render.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
$relatedPostId = $attributes['relatedPostId'] ?? null;
|
||||||
|
$postType = get_post_type_object(get_post_type($relatedPostId));
|
||||||
|
|
||||||
|
$relatedPost = get_post($relatedPostId) ?? null;
|
||||||
|
$relatedPostUrl = get_permalink($relatedPostId) ?? null;
|
||||||
|
$cover = get_field('cover', $relatedPostId) ?? null;
|
||||||
|
$target = $postType->name === 'fiches-infos' ? "_blank" : "_self";
|
||||||
|
$thematique = get_the_terms($relatedPostId, 'thematiques')[0];
|
||||||
|
$mainThematique = getMainThematique($thematique);
|
||||||
|
$thematiqueColorSlug = $mainThematique->slug;
|
||||||
|
$thematique_icon = get_field('taxonomy_pictures', 'thematiques' . '_' . $mainThematique->term_id)['icon'];
|
||||||
|
// echo '<pre>';
|
||||||
|
// print_r($postType);
|
||||||
|
// echo '</pre>';
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
<a class="post-card" href="<?php echo $relatedPostUrl ?>" target="<?php echo $target ?>">
|
||||||
|
|
||||||
|
<img class="post-card__cover" src="<?php echo $thematique_icon['url'] ?>" alt="">
|
||||||
|
|
||||||
|
<div class="post-card__details">
|
||||||
|
<div class="post-card__tags">
|
||||||
|
|
||||||
|
<?php if ($mainThematique) : ?>
|
||||||
|
<div class="tag thematique-tag thematique-tag--<?php echo $mainThematique->slug ?>"><?php echo $mainThematique->name ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<div class="tag post-type-tag"><?php echo $postType->label ?></div>
|
||||||
|
</div>
|
||||||
|
<h2 class="post-card__title"><?php echo $relatedPost->post_title ?></h2>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
14
blocks/post-card/build/style-index.css
Normal file
14
blocks/post-card/build/style-index.css
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
/*!**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
|
||||||
|
!*** 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 ***!
|
||||||
|
\**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
|
||||||
|
/**
|
||||||
|
* The following styles get applied both on the front of your site
|
||||||
|
* and in the editor.
|
||||||
|
*
|
||||||
|
* Replace them with your own styles or remove the file completely.
|
||||||
|
*/
|
||||||
|
.parcours-step-container h2 {
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*# sourceMappingURL=style-index.css.map*/
|
||||||
1
blocks/post-card/build/style-index.css.map
Normal file
1
blocks/post-card/build/style-index.css.map
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"./style-index.css","mappings":";;;AAAA;;;;;EAAA;AAQC;EACC;AADF,C","sources":["webpack://multiblocks/./src/style.scss"],"sourcesContent":["/**\n * The following styles get applied both on the front of your site\n * and in the editor.\n *\n * Replace them with your own styles or remove the file completely.\n */\n\n.parcours-step-container {\n\th2 {\n\t\tfont-weight: 800;\n\t}\n}\n"],"names":[],"sourceRoot":""}
|
||||||
20
blocks/post-card/package.json
Normal file
20
blocks/post-card/package.json
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"name": "multiblocks",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Example block scaffolded with Create Block tool.",
|
||||||
|
"author": "The WordPress Contributors",
|
||||||
|
"license": "GPL-2.0-or-later",
|
||||||
|
"main": "build/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "wp-scripts build",
|
||||||
|
"format": "wp-scripts format",
|
||||||
|
"lint:css": "wp-scripts lint-style",
|
||||||
|
"lint:js": "wp-scripts lint-js",
|
||||||
|
"packages-update": "wp-scripts packages-update",
|
||||||
|
"plugin-zip": "wp-scripts plugin-zip",
|
||||||
|
"start": "wp-scripts start"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@wordpress/scripts": "^26.9.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
10956
blocks/post-card/pnpm-lock.yaml
Normal file
10956
blocks/post-card/pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load Diff
128
blocks/post-card/src/OptionsSelectControl.js
Normal file
128
blocks/post-card/src/OptionsSelectControl.js
Normal file
|
|
@ -0,0 +1,128 @@
|
||||||
|
import { __ } from "@wordpress/i18n";
|
||||||
|
import { InspectorControls } from "@wordpress/block-editor";
|
||||||
|
import {
|
||||||
|
PanelBody,
|
||||||
|
SelectControl,
|
||||||
|
ComboboxControl,
|
||||||
|
} from "@wordpress/components";
|
||||||
|
import "./editor.scss";
|
||||||
|
import { Tip } from "@wordpress/components";
|
||||||
|
|
||||||
|
import { useSelect } from "@wordpress/data";
|
||||||
|
import { useEffect, useState } from "@wordpress/element";
|
||||||
|
import { decodeEntities } from "@wordpress/html-entities";
|
||||||
|
|
||||||
|
export default function OptionsSelectControl({
|
||||||
|
setAttributes,
|
||||||
|
relatedPostId,
|
||||||
|
postType,
|
||||||
|
}) {
|
||||||
|
if (!postType || !setAttributes) return <p>Loading</p>;
|
||||||
|
|
||||||
|
let [postOptions, setPostOptions] = useState(null);
|
||||||
|
|
||||||
|
const lang = getAdminLanguageFromCookie("wp-wpml_current_language");
|
||||||
|
const optionPages = useSelect(
|
||||||
|
(select) => {
|
||||||
|
if (!postType) return null;
|
||||||
|
let query = {
|
||||||
|
status: "publish",
|
||||||
|
per_page: -1,
|
||||||
|
lang: lang,
|
||||||
|
};
|
||||||
|
return select("core").getEntityRecords("postType", postType, query);
|
||||||
|
},
|
||||||
|
[postType, lang],
|
||||||
|
);
|
||||||
|
const editUrl = relatedPostId
|
||||||
|
? `${window.location.origin}/wp-admin/post.php?post=${relatedPostId}&action=edit`
|
||||||
|
: null;
|
||||||
|
function getAdminLanguageFromCookie(c_name) {
|
||||||
|
var c_value = document.cookie,
|
||||||
|
c_start = c_value.indexOf(" " + c_name + "=");
|
||||||
|
if (c_start == -1) c_start = c_value.indexOf(c_name + "=");
|
||||||
|
if (c_start == -1) {
|
||||||
|
c_value = null;
|
||||||
|
} else {
|
||||||
|
c_start = c_value.indexOf("=", c_start) + 1;
|
||||||
|
var c_end = c_value.indexOf(";", c_start);
|
||||||
|
if (c_end == -1) {
|
||||||
|
c_end = c_value.length;
|
||||||
|
}
|
||||||
|
c_value = unescape(c_value.substring(c_start, c_end));
|
||||||
|
}
|
||||||
|
return c_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleRelatedPostChange(postId) {
|
||||||
|
setAttributes({ relatedPostId: Number(postId) });
|
||||||
|
}
|
||||||
|
function handlePostTypeChange(postType) {
|
||||||
|
setAttributes({ postType: postType, relatedPostId: null });
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildSelectOptions(optionPages) {
|
||||||
|
let options = [];
|
||||||
|
if (optionPages && optionPages.length > 0) {
|
||||||
|
options.push({ value: 0, label: "Selectionnez une page" });
|
||||||
|
optionPages.forEach((page) => {
|
||||||
|
options.push({
|
||||||
|
value: page.id,
|
||||||
|
label: decodeEntities(page.title.rendered),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
options.push({ value: 0, label: "Pas encore de questions..." });
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!optionPages || !postType) return;
|
||||||
|
if (optionPages && optionPages.length > 0) {
|
||||||
|
setPostOptions(buildSelectOptions(optionPages));
|
||||||
|
}
|
||||||
|
}, [optionPages, postType]);
|
||||||
|
|
||||||
|
let panelTitle = "Post Reliée";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<InspectorControls>
|
||||||
|
<PanelBody title={__("Contenu Reliée", "homegrade-blocks")}>
|
||||||
|
<SelectControl
|
||||||
|
label={__("Type de post", "homegrade-blocks")}
|
||||||
|
options={[
|
||||||
|
{ value: "conseils", label: "Conseils" },
|
||||||
|
{ value: "fiches-infos", label: "Fiches infos" },
|
||||||
|
{ value: "questions", label: "Questions" },
|
||||||
|
{ value: "videos-webinaires", label: "Videos / Webinaires" },
|
||||||
|
]}
|
||||||
|
value={postType ?? null}
|
||||||
|
onChange={handlePostTypeChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{postOptions && (
|
||||||
|
<ComboboxControl
|
||||||
|
label={panelTitle}
|
||||||
|
value={relatedPostId}
|
||||||
|
options={postOptions}
|
||||||
|
onChange={(e) => handleRelatedPostChange(e)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{relatedPostId && (
|
||||||
|
<Tip>
|
||||||
|
{__(
|
||||||
|
"Pour modifier le contenu de la question affichée ici, rendez-vous dans la fiche question correspondante.",
|
||||||
|
"homegrade-blocks",
|
||||||
|
)}
|
||||||
|
</Tip>
|
||||||
|
)}
|
||||||
|
{relatedPostId && editUrl && (
|
||||||
|
<a href={editUrl} className="edit-question-button">
|
||||||
|
Éditer le post
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</PanelBody>
|
||||||
|
</InspectorControls>
|
||||||
|
);
|
||||||
|
}
|
||||||
27
blocks/post-card/src/block.json
Normal file
27
blocks/post-card/src/block.json
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||||
|
"apiVersion": 2,
|
||||||
|
"name": "homegrade-content-blocks/post-card",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"title": "Post Card",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
115
blocks/post-card/src/edit.js
Normal file
115
blocks/post-card/src/edit.js
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
import { __ } from "@wordpress/i18n";
|
||||||
|
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 { useEntityProp } from "@wordpress/core-data";
|
||||||
|
|
||||||
|
export default function Edit({ attributes, setAttributes }) {
|
||||||
|
const { relatedPostId, postType } = attributes;
|
||||||
|
|
||||||
|
const currentRelatedPost = useSelect(
|
||||||
|
(select) =>
|
||||||
|
relatedPostId && postType
|
||||||
|
? select("core").getEntityRecord("postType", postType, relatedPostId)
|
||||||
|
: null,
|
||||||
|
[relatedPostId, postType],
|
||||||
|
);
|
||||||
|
|
||||||
|
const post = useSelect((select) =>
|
||||||
|
select("core").getEntityRecord("postType", postType, relatedPostId),
|
||||||
|
);
|
||||||
|
|
||||||
|
const postMainTaxonomy = useSelect(
|
||||||
|
(select) => {
|
||||||
|
return select("core").getEntityRecord(
|
||||||
|
"taxonomy",
|
||||||
|
"thematiques",
|
||||||
|
post?.thematiques ?? null,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[post],
|
||||||
|
);
|
||||||
|
|
||||||
|
const postParentTaxonomy = useSelect(
|
||||||
|
(select) => {
|
||||||
|
if (!postMainTaxonomy) return null;
|
||||||
|
if (postMainTaxonomy && !postMainTaxonomy.parent) return postMainTaxonomy;
|
||||||
|
return select("core").getEntityRecord(
|
||||||
|
"taxonomy",
|
||||||
|
"thematiques",
|
||||||
|
postMainTaxonomy?.parent ?? null,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[postMainTaxonomy],
|
||||||
|
);
|
||||||
|
|
||||||
|
const thematiqueCoverUrl = useSelect(
|
||||||
|
(select) => {
|
||||||
|
let thematiqueMediaId = postParentTaxonomy?.acf?.taxonomy_pictures?.icon;
|
||||||
|
const media = select("core").getMedia(thematiqueMediaId);
|
||||||
|
return media?.source_url ?? null;
|
||||||
|
},
|
||||||
|
[postParentTaxonomy],
|
||||||
|
);
|
||||||
|
|
||||||
|
const postTypeDatas = useSelect((select) =>
|
||||||
|
select("core").getEntityConfig("postType", postType),
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<OptionsSelectControl
|
||||||
|
relatedPostId={relatedPostId}
|
||||||
|
postType={postType}
|
||||||
|
setAttributes={setAttributes}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
{...useBlockProps({
|
||||||
|
className: `post-card`,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{/* postParentTaxonomy */}
|
||||||
|
<img class="post-card__cover" alt="" src={thematiqueCoverUrl} />
|
||||||
|
<div class="post-card__details">
|
||||||
|
<div class="post-card__tags">
|
||||||
|
{postParentTaxonomy && (
|
||||||
|
<div
|
||||||
|
class={
|
||||||
|
"tag thematique-tag thematique-tag--" +
|
||||||
|
postParentTaxonomy.slug
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{postParentTaxonomy.name}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{postTypeDatas && (
|
||||||
|
<div class="tag post-type-tag">{postTypeDatas.label}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{currentRelatedPost && currentRelatedPost.title && (
|
||||||
|
<h2 class="post-card__title">
|
||||||
|
{decodeEntities(currentRelatedPost.title.rendered)}
|
||||||
|
</h2>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{!relatedPostId && (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
{__(
|
||||||
|
"Ce bloc n'est relié à aucun post. Rattachez-le à un post dans la barre latérale.",
|
||||||
|
"homegrade-blocks__texte-backoffice",
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
10
blocks/post-card/src/editor.scss
Normal file
10
blocks/post-card/src/editor.scss
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* The following styles get applied inside the editor only.
|
||||||
|
*
|
||||||
|
* Replace them with your own styles or remove the file completely.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.post-content-container{
|
||||||
|
opacity: 50%;
|
||||||
|
filter: saturate(90%);
|
||||||
|
}
|
||||||
29
blocks/post-card/src/index.js
Normal file
29
blocks/post-card/src/index.js
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { registerBlockType } from "@wordpress/blocks";
|
||||||
|
|
||||||
|
import "./style.scss";
|
||||||
|
|
||||||
|
import Edit from "./edit";
|
||||||
|
import metadata from "./block.json";
|
||||||
|
|
||||||
|
registerBlockType(metadata.name, {
|
||||||
|
icon: {
|
||||||
|
src: (
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="62.01"
|
||||||
|
height="58.04"
|
||||||
|
viewBox="0 0 62.01 58.04"
|
||||||
|
>
|
||||||
|
<g>
|
||||||
|
<path
|
||||||
|
class="cls-1"
|
||||||
|
d="M14.68,21.37c5.73-2.02,8.73-8.31,6.71-14.04C19.36,1.61,13.08-1.39,7.35.63,1.62,2.66-1.38,8.94.64,14.67c1.11,3.13,3.57,5.6,6.71,6.71l.67.24v14.82l-.68.23c-5.73,2.02-8.73,8.31-6.71,14.04,2.02,5.73,8.31,8.73,14.04,6.71,5.73-2.02,8.73-8.31,6.71-14.04-1.11-3.13-3.57-5.6-6.71-6.71l-.66-.23v-14.82l.67-.24ZM16.01,47.02c0,2.76-2.24,5-5,5s-5-2.24-5-5,2.24-5,5-5,5,2.24,5,5ZM11.01,16.02c-2.76,0-5-2.24-5-5s2.24-5,5-5,5,2.24,5,5-2.24,5-5,5ZM34.01,8.02h25c1.66,0,3-1.34,3-3s-1.34-3-3-3h-25c-1.66,0-3,1.34-3,3s1.34,3,3,3ZM59.01,18.02h-25c-1.66,0-3,1.34-3,3s1.34,3,3,3h25c1.66,0,3-1.34,3-3s-1.34-3-3-3ZM59.01,34.02h-25c-1.66,0-3,1.34-3,3s1.34,3,3,3h25c1.66,0,3-1.34,3-3s-1.34-3-3-3ZM59.01,50.02h-25c-1.66,0-3,1.34-3,3s1.34,3,3,3h25c1.66,0,3-1.34,3-3s-1.34-3-3-3Z"
|
||||||
|
/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
),
|
||||||
|
foreground: "#DF1E1E",
|
||||||
|
},
|
||||||
|
|
||||||
|
edit: Edit,
|
||||||
|
});
|
||||||
33
blocks/post-card/src/render.php
Normal file
33
blocks/post-card/src/render.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
$relatedPostId = $attributes['relatedPostId'] ?? null;
|
||||||
|
$postType = get_post_type_object(get_post_type($relatedPostId));
|
||||||
|
|
||||||
|
$relatedPost = get_post($relatedPostId) ?? null;
|
||||||
|
$relatedPostUrl = get_permalink($relatedPostId) ?? null;
|
||||||
|
$cover = get_field('cover', $relatedPostId) ?? null;
|
||||||
|
$target = $postType->name === 'fiches-infos' ? "_blank" : "_self";
|
||||||
|
$thematique = get_the_terms($relatedPostId, 'thematiques')[0];
|
||||||
|
$mainThematique = getMainThematique($thematique);
|
||||||
|
$thematiqueColorSlug = $mainThematique->slug;
|
||||||
|
$thematique_icon = get_field('taxonomy_pictures', 'thematiques' . '_' . $mainThematique->term_id)['icon'];
|
||||||
|
// echo '<pre>';
|
||||||
|
// print_r($postType);
|
||||||
|
// echo '</pre>';
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
<a class="post-card" href="<?php echo $relatedPostUrl ?>" target="<?php echo $target ?>">
|
||||||
|
|
||||||
|
<img class="post-card__cover" src="<?php echo $thematique_icon['url'] ?>" alt="">
|
||||||
|
|
||||||
|
<div class="post-card__details">
|
||||||
|
<div class="post-card__tags">
|
||||||
|
|
||||||
|
<?php if ($mainThematique) : ?>
|
||||||
|
<div class="tag thematique-tag thematique-tag--<?php echo $mainThematique->slug ?>"><?php echo $mainThematique->name ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<div class="tag post-type-tag"><?php echo $postType->label ?></div>
|
||||||
|
</div>
|
||||||
|
<h2 class="post-card__title"><?php echo $relatedPost->post_title ?></h2>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
12
blocks/post-card/src/style.scss
Normal file
12
blocks/post-card/src/style.scss
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
/**
|
||||||
|
* The following styles get applied both on the front of your site
|
||||||
|
* and in the editor.
|
||||||
|
*
|
||||||
|
* Replace them with your own styles or remove the file completely.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.parcours-step-container {
|
||||||
|
h2 {
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user