Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Allow blocks with supports align to have a default alignment #9338

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Aug 24, 2018

Description

Supports align option allow blocks to have an alignment option (toolbar, attributes, and class names in the editor and save) with just one line. That is awesome to avoid duplicate code.
But if we need a block with supports align but also have a default alignment (e.g: right) that was not possible.
This Pr's makes sure blocks can use supports align and have a default alignment. To do that blocks have to provide their own align attribute definition with the default option set.

How has this been tested?

I used the following test block https://gist.github.com/jorgefilipecosta/d3cc0a9937ac1105e0a0537efd0e615b and checked the default align right is applied.

@jorgefilipecosta jorgefilipecosta changed the title Update: Allow blocks with supports align to change to have a default alignment Update: Allow blocks with supports align to have a default alignment Aug 24, 2018
@0aveRyan
Copy link
Contributor

This seems particularly helpful to help news publishers automate Outbrain/Paid Ads/In-House ad insertion.

Currently, many plugins guess where it's safe for publishers to insert ads, and forcing in-content alignment like this is a common news design pattern (example from CNN below).

screen shot 2018-08-24 at 4 40 49 pm

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@@ -23,6 +23,9 @@ import { BlockControls, BlockAlignmentToolbar } from '../components';
* @return {Object} Filtered block settings
*/
export function addAttribute( settings ) {
if ( has( settings, [ 'attributes', 'align' ] ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check if it has a proper type === string?

@jorgefilipecosta jorgefilipecosta force-pushed the update/allow-blocks-with-supports-align-to-have-default branch from 032c003 to ddda54a Compare August 28, 2018 15:48
@jorgefilipecosta jorgefilipecosta merged commit a87b808 into master Aug 29, 2018
@jorgefilipecosta jorgefilipecosta deleted the update/allow-blocks-with-supports-align-to-have-default branch August 29, 2018 11:30
@@ -23,6 +23,10 @@ import { BlockControls, BlockAlignmentToolbar } from '../components';
* @return {Object} Filtered block settings
*/
export function addAttribute( settings ) {
// allow blocks to specify their own attribute definition with default values if needed.
if ( get( settings.attributes, [ 'align', 'type' ] ) === 'string' ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we specifically check the type? Would it be okay for us to override the attribute definition if it was a type other than string ? Would has( settings.attributes, [ 'align' ] ) not have been sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are checking the type because when using the align hook the hook is the one setting the align value and the hook sets a string, so specifying an attribute with a different type would not work correctly.
When setting supports align the expectation is that the hook will work properly so in this case for the hook to work properly we need to change the align attribute, I think it is acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants