Skip to content

Commit

Permalink
Add secret to block editor (entryfield).
Browse files Browse the repository at this point in the history
  • Loading branch information
doekenorg committed Feb 8, 2024
1 parent dfe5808 commit 870c61a
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 7 deletions.
4 changes: 3 additions & 1 deletion future/includes/class-gv-shortcode-gvfield.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function callback( $atts, $content = '', $tag = '' ) {
*/
$atts = apply_filters( 'gravityview/shortcodes/gvfield/atts', $atts );

if ( ! $view = \GV\View::by_id( $atts['view_id'] ) ) {
$view = $this->get_view_by_atts( $atts );

if ( ! $view ) {
gravityview()->log->error( 'View #{view_id} not found', array( 'view_id' => $atts['view_id'] ) );
return apply_filters( 'gravityview/shortcodes/gvfield/output', '', $view, null, null, $atts );
}
Expand Down
4 changes: 4 additions & 0 deletions future/includes/gutenberg/blocks/entry-field/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"default": "",
"type": "string"
},
"secret": {
"default": null,
"type": "string"
},
"entryId": {
"default": "",
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions future/includes/gutenberg/blocks/entry-field/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function modify_block_meta( $block_meta ) {
static function render( $block_attributes = array() ) {
$block_to_shortcode_attributes_map = array(
'viewId' => 'view_id',
'secret' => 'secret',
'entryId' => 'entry_id',
'fieldId' => 'field_id',
'fieldSettingOverrides' => 'field_setting_overrides',
Expand Down
11 changes: 10 additions & 1 deletion future/includes/gutenberg/blocks/entry-field/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {
<ViewSelector
viewId={ viewId }
isSidebar={ true }
onChange={ ( viewId ) => { setAttributes( { viewId, previewBlock: false, entryId: '' } ); } }
onChange={ ( _viewId ) => {
const selectedView = gkGravityViewBlocks.views.find( option => option.value === _viewId );

setAttributes( {
viewId: _viewId,
secret: selectedView?.secret,
previewBlock: false,
entryId: '',
} );
} }
/>

<EntrySelector
Expand Down
4 changes: 4 additions & 0 deletions future/includes/gutenberg/blocks/entry/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"default": "",
"type": "string"
},
"secret": {
"default": null,
"type": "string"
},
"entryId": {
"default": "",
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions future/includes/gutenberg/blocks/entry/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static function render( $block_attributes = array() ) {
$block_to_shortcode_attributes_map = array(
'entryId' => 'id',
'viewId' => 'view_id',
'secret' => 'secret',
);

$shortcode_attributes = array();
Expand Down
11 changes: 10 additions & 1 deletion future/includes/gutenberg/blocks/entry/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {
<ViewSelector
viewId={ viewId }
isSidebar={ true }
onChange={ ( viewId ) => setAttributes( { viewId, previewBlock: false, entryId: '' } ) }
onChange={ ( _viewId ) => {
const selectedView = gkGravityViewBlocks.views.find( option => option.value === _viewId );

setAttributes( {
viewId: _viewId,
secret: selectedView?.secret,
previewBlock: false,
entryId: '',
} );
} }
/>

<EntrySelector
Expand Down
2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/entry-field.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '96105f7e7c66ae854b16');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'e1c7e2017a5f9aad2b57');
2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/entry-field.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/entry.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '537a27e82c3d99cbf2c1');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'cba090107cff4bd0fdec');
2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/entry.js

Large diffs are not rendered by default.

0 comments on commit 870c61a

Please sign in to comment.