Skip to content

Commit

Permalink
Issue #34 - support the bw_pages shortcode format= parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Oct 26, 2020
1 parent 562730d commit 9fa9c82
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 2 deletions.
7 changes: 7 additions & 0 deletions blocks/oik-content/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const shortcode_attributes =
default: 'desc',
},

format: {
type: 'string',
default: 'LIER',
},

// categories=
// category_name=
// customcategoryname=
Expand Down Expand Up @@ -82,4 +87,6 @@ const order =

];



export { shortcode_attributes, orderby, order };
6 changes: 5 additions & 1 deletion blocks/oik-content/bw_shortcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ const bw_shortcodes = {
// ,"bw_popup":"Display a popup after a timed delay"
//,"bw_portfolio":"Display matched portfolio files"
//,"bw_post":"Add Post button"
,"bw_posts":"Display posts"

//
// bw_posts simply calls bw_list so we only need bw_list really
// all it does is to set parameters to default to the 10 most recent posts.
//,"bw_posts":"Display posts"
//,"bw_power":"Powered by WordPress"
//,"bw_qrcode":"Display an uploaded QR code image"
//,"bw_register":"Display a link to the Registration form, if Registration is enabled
Expand Down
6 changes: 6 additions & 0 deletions blocks/oik-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {bw_shortcodes, getAttributes} from "./bw_shortcodes";
import {PostTypes} from "./post_type";
import{ NumberPosts } from './numberposts';
import { orderby, order } from './attributes';
import { Formats } from './formats';

const edit= withInstanceId(
( { attributes, setAttributes, instanceId, isSelected } ) => {
Expand Down Expand Up @@ -89,6 +90,10 @@ const edit= withInstanceId(
setAttributes( { order: value } );
}

const onChangeFormat = ( value ) => {
setAttributes( { format: value } );
}

/*
<GenericAttrs value={attributes.shortcode} />
*/
Expand All @@ -107,6 +112,7 @@ const edit= withInstanceId(
<SelectControl label="Order" value={ attributes.order} options={ order} onChange={onChangeOrder} />
<RangeControl label="Number posts" value={ attributes.numberposts } onChange={ onChangeNumberPosts } min={-1} max={100} />
<TextControl value={ attributes.post_parent} onChange={ onChangePostParent } label="Post Parent" />
<Formats value={attributes.format} onChange={onChangeFormat} />

<TextareaControl label="Advanced Parameters"
value={ attributes.parameters }
Expand Down
72 changes: 72 additions & 0 deletions blocks/oik-content/formats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const format_options = [
{ label: 'Default', value: 'LIER',},
{ label: 'Link,image', value: 'LI', },
{ label: 'Link, image, excerpt', value: 'LIE' },
{ label: 'Image, link', value: 'IL', },
{ label: 'Image, link, excerpt', value: 'ILE' },
{ label: 'Link, Image, Date, Author', value: 'LI/d/a'},
{ label: 'None', value: '' },
];

const single_format_options = [
{ label: 'None', value: null, },
{ label: 'Title', value: 'T', },
{ label: 'Link', value: 'L', },
{ label: 'Image', value: 'I', },
{ label: 'Excerpt', value: 'E', },
{ label: 'Read more', value: 'R', },
{ label: 'Div', value: '/', },
{ label: 'Fields', value: '_',},
{ label: 'Space', value: ' ',},
{ label: 'Content', value: 'C',},
{ label: 'Categories', value: 'c', },
{ label: 'Tags', value: 't'},
{ label: 'Author', value: 'a'},
{ label: 'Date', value: 'd' },
{ label: 'Edit', value: 'e' },
];

const { select, subscribe } = wp.data;
const { Component } = wp.element;
const { SelectControl } = wp.components;

export class Formats extends Component {
constructor() {
super(...arguments);
this.state = {
formats: format_options,
};
}

formatsSelect( props ) {
var formats = this.state.formats;
if (formats) {
//var options = formats.map((format) => this.formatsOption(format));
return (
<SelectControl label="Format" value={this.props.format}
options={format_options}
onChange={this.props.onChange}
/>
);
} else {
return (<p>Loading formats</p>);
}
}



/**
* Map the format_option to a select list option
*
* @param format
* @returns {{label: *, value: *}}
*/
formatOption( format ) {
return( { value: format.value, label: format.label });
}

render() {
return( this.formatsSelect()
);
}
}
14 changes: 13 additions & 1 deletion oik-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ function oik_blocks_loaded() {
add_action( "plugins_loaded", "oik_blocks_plugins_loaded", 100 );

add_action( "init", "oik_blocks_register_dynamic_blocks" );
add_action( 'init', 'oik_blocks_register_block_patterns' );
// herbs_hack was an action added to Gutenberg's client-assets.php when expirementing with pattern registration
//add_action( 'herbs_hack', 'oik_blocks_register_block_patterns' );
add_action( "oik_pre_theme_field", "oik_blocks_pre_theme_field" );


Expand Down Expand Up @@ -645,7 +648,8 @@ function oik_blocks_register_dynamic_blocks() {
, 'numberposts' => ['type' => 'integer']
, 'orderby' => [ 'type' => 'string' ]
, 'order' => [ 'type' => 'string' ]

, 'align' => [ 'type' => 'string']
, 'format' => ['type' => 'string']
]
] );

Expand All @@ -658,6 +662,14 @@ function oik_blocks_maybe_register_block_type( $name, $args ) {
}
}

function oik_blocks_register_block_patterns() {
if ( false ) {
oik_require( 'patterns/index.php', 'oik-blocks' );
oik_blocks_lazy_register_block_patterns();
}
}


/**
* Registers the scripts we'll need for the editor
*
Expand Down

0 comments on commit 9fa9c82

Please sign in to comment.