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
3642d07c
Commit
3642d07c
authored
3 years ago
by
Bruno Antunes Magrini
Browse files
Options
Download
Email Patches
Plain Diff
adiciona verificação de chave de api no bloco hacklab-video-playlist
parent
e41d9f41
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
8 deletions
+43
-8
blocks/hacklab-video-playlist/edit.js
blocks/hacklab-video-playlist/edit.js
+26
-8
blocks/hacklab-video-playlist/hacklab-video-playlist.php
blocks/hacklab-video-playlist/hacklab-video-playlist.php
+17
-0
No files found.
blocks/hacklab-video-playlist/edit.js
View file @
3642d07c
...
...
@@ -7,6 +7,7 @@
import
{
TextControl
,
SelectControl
,
__experimentalNumberControl
as
NumberControl
}
from
'
@wordpress/components
'
;
import
{
__
}
from
"
@wordpress/i18n
"
;
import
React
,
{
useCallback
,
useSelect
,
useState
,
useEffect
}
from
'
react
'
;
/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
...
...
@@ -27,17 +28,32 @@ import { useBlockProps } from '@wordpress/block-editor';
*
* @return {WPElement} Element to render.
*/
export
default
function
Edit
(
{
attributes
:
{
title
,
youtubeFormat
,
youtubeId
,
numItems
,
style
import
apiFetch
from
'
@wordpress/api-fetch
'
;
// GET
export
default
function
Edit
(
{
attributes
:
{
title
,
youtubeFormat
,
youtubeId
,
numItems
,
style
},
setAttributes
}
)
{
const
[
youtubeKey
,
setyoutubeKey
]
=
useState
(
''
);
useEffect
(()
=>
{
apiFetch
(
{
path
:
'
hacklab-blocks/v1/options/
'
}
).
then
(
(
option
)
=>
{
setyoutubeKey
(
option
);
}
);
},
setAttributes
}
)
{
[]);
return
(
<>
{
!
youtubeKey
?
<
div
>
Preencha
a
chave
do
youtube
nas
configurações
para
utilizar
o
bloco
video
-
playlist
<
/div
>
:
<
div
className
=
"
video-gallery-wrapper
"
key
=
"
container
"
>
<
div
>
<
TextControl
...
...
@@ -93,6 +109,8 @@ export default function Edit( {
<
/div
>
<
/div
>
}
<
/
>
);
}
This diff is collapsed.
Click to expand it.
blocks/hacklab-video-playlist/hacklab-video-playlist.php
View file @
3642d07c
...
...
@@ -194,3 +194,20 @@ function hacklab_video_playlist_callback( $attributes = [] ) {
return
$embeds
;
}
// Cria endpoint para o pegar youtub id das options
function
api_get_option
(
$data
)
{
$option
=
get_option
(
'youtube_key'
);
if
(
empty
(
$option
)
)
{
return
null
;
}
return
$option
;
}
add_action
(
'rest_api_init'
,
function
()
{
register_rest_route
(
'hacklab-blocks/v1'
,
'/options/'
,
array
(
'methods'
=>
'GET'
,
'callback'
=>
'hacklabBlocks\api_get_option'
,
'permission_callback'
=>
function
()
{
return
current_user_can
(
'edit_others_posts'
);
}
));
});
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