Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
open-source
hacklab-blocks
Commits
731cb33b
Commit
731cb33b
authored
2 years ago
by
Bruno Antunes Magrini
Browse files
Options
Download
Email Patches
Plain Diff
adiciona alguns testes no loop e alterações no edit.js
parent
d444631b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
62 deletions
+24
-62
blocks/custom-taxonomy/custom-taxonomy.php
blocks/custom-taxonomy/custom-taxonomy.php
+22
-31
blocks/custom-taxonomy/edit.js
blocks/custom-taxonomy/edit.js
+2
-30
blocks/hacklab-fetch-posts-api/edit.js
blocks/hacklab-fetch-posts-api/edit.js
+0
-1
No files found.
blocks/custom-taxonomy/custom-taxonomy.php
View file @
731cb33b
...
...
@@ -54,40 +54,31 @@ function render_block_core_post_terms_2($attributes, $content, $block)
$tax_terms
=
[];
if
(
is_taxonomy_viewable
(
$taxonomy
))
{
$tax_terms
=
get_the_terms
(
$block
->
context
[
'postId'
],
$taxonomy
);
$post_terms
=
array_merge
(
$post_terms
,
$tax_terms
);
if
(
is_array
(
$tax_terms
)){
$post_terms
=
array_merge
(
$post_terms
,
$tax_terms
);
}
}
}
if
(
is_wp_error
(
$post_terms
)
||
empty
(
$post_terms
))
{
return
''
;
}
if
(
isset
(
$attributes
[
'textAlign'
]))
{
$classes
.
=
' has-text-align-'
.
$attributes
[
'textAlign'
];
}
$separator
=
empty
(
$attributes
[
'separator'
])
?
' '
:
$attributes
[
'separator'
];
$wrapper_attributes
=
get_block_wrapper_attributes
(
array
(
'class'
=>
$classes
));
echo
'<pre>'
;
print_r
(
$post_terms
);
echo
'</pre>'
;
$html_array
=
[];
foreach
(
$post_terms
as
$term
)
{
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link
=
get_term_link
(
$term
);
// If there was an error, continue to the next term.
if
(
is_wp_error
(
$term_link
))
{
continue
;
$html
=
''
;
if
(
count
(
$post_terms
)){
$separator
=
empty
(
$attributes
[
'separator'
])
?
' '
:
$attributes
[
'separator'
];
$wrapper_attributes
=
get_block_wrapper_attributes
(
array
(
'class'
=>
$classes
));
$html_array
=
[];
foreach
(
$post_terms
as
$term
)
{
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link
=
get_term_link
(
$term
);
// If there was an error, continue to the next term.
if
(
is_wp_error
(
$term_link
))
{
continue
;
}
// We successfully got a link. Print it out.
$html_array
[]
=
'<a clases="post-term-'
.
$term
->
slug
.
' post-taxonomy-'
.
$term
->
taxonomy
.
' " href="'
.
esc_url
(
$term_link
)
.
'">'
.
$term
->
name
.
'</a>'
;
}
// We successfully got a link. Print it out.
$html_array
[]
=
'<a clases="post-term-'
.
$term
->
slug
.
' post-taxonomy-'
.
$term
->
taxonomy
.
' " href="'
.
esc_url
(
$term_link
)
.
'">'
.
$term
->
name
.
'</a>'
;
$html
=
implode
(
$separator
,
$html_array
);
}
$html
=
implode
(
$separator
,
$html_array
);
return
$html
;
}
This diff is collapsed.
Click to expand it.
blocks/custom-taxonomy/edit.js
View file @
731cb33b
...
...
@@ -28,7 +28,7 @@ import {
import
{
useSelect
}
from
'
@wordpress/data
'
;
import
{
__
}
from
'
@wordpress/i18n
'
;
import
{
store
as
coreStore
}
from
'
@wordpress/core-data
'
;
import
ServerSideRender
from
'
@wordpress/server-side-render
'
;
/**
* Internal dependencies
*/
...
...
@@ -42,7 +42,6 @@ export default function Edit(props) {
const
{
postId
,
postType
}
=
context
;
const
ctaxblock
=
window
.
ctaxblock
const
taxonomies
=
ctaxblock
.
taxPerPt
[
postType
]
console
.
log
(
selectedTax
);
const
selectedTerm
=
useSelect
(
(
select
)
=>
{
if
(
!
term
)
return
{};
...
...
@@ -96,34 +95,7 @@ export default function Edit(props) {
<
/PanelBody
>
<
/Panel
>
<
/InspectorControls
>
<
div
{...
blockProps
}
>
{
isLoading
&&
<
Spinner
/>
}
{
!
isLoading
&&
hasPostTerms
&&
postTerms
.
map
((
postTerm
)
=>
(
<
a
key
=
{
postTerm
.
id
}
href
=
{
postTerm
.
link
}
onClick
=
{(
event
)
=>
event
.
preventDefault
()}
>
{
unescape
(
postTerm
.
name
)}
<
/a
>
))
.
reduce
((
prev
,
curr
)
=>
(
<>
{
prev
}
<
span
className
=
"
wp-block-post-terms__separator
"
>
{
separator
||
'
'
}
<
/span
>
{
curr
}
<
/
>
))}
{
!
isLoading
&&
!
hasPostTerms
&&
(
selectedTerm
?.
labels
?.
no_terms
||
__
(
'
Term items not found.
'
))}
<
/div
>
termos
de
taxonomia
<
/div
>
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blocks/hacklab-fetch-posts-api/edit.js
View file @
731cb33b
...
...
@@ -58,7 +58,6 @@
setAttributes
,
}
=
props
;
console
.
log
(
props
);
const
{
titleBlock
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment