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 ( <>
{/* postParentTaxonomy */}
{postParentTaxonomy && (
{postParentTaxonomy.name}
)} {postTypeDatas && (
{postTypeDatas.label}
)}
{currentRelatedPost && currentRelatedPost.title && (

{decodeEntities(currentRelatedPost.title.rendered)}

)}
{!relatedPostId && ( <>

{__( "Ce bloc n'est relié à aucun post. Rattachez-le à un post dans la barre latérale.", "homegrade-blocks__texte-backoffice", )}

)}
); }