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

Merged
merged 1 commit into from Aug 29, 2018

Conversation

Projects
None yet
4 participants
@jorgefilipecosta
Member

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 from Update: Allow blocks with supports align to change to have a default alignment to Update: Allow blocks with supports align to have a default alignment Aug 24, 2018

@0aveRyan

This comment has been minimized.

Show comment
Hide comment
@0aveRyan

0aveRyan Aug 24, 2018

Member

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

Member

0aveRyan commented Aug 24, 2018

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

@gziolo

gziolo approved these changes Aug 28, 2018

LGTM 👍

Show outdated Hide outdated packages/editor/src/hooks/align.js

@jorgefilipecosta jorgefilipecosta merged commit a87b808 into master Aug 29, 2018

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details

@jorgefilipecosta jorgefilipecosta deleted the update/allow-blocks-with-supports-align-to-have-default branch Aug 29, 2018

@@ -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' ) {

This comment has been minimized.

@aduth

aduth Aug 29, 2018

Member

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?

@aduth

aduth Aug 29, 2018

Member

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?

This comment has been minimized.

@jorgefilipecosta

jorgefilipecosta Aug 29, 2018

Member

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.

@jorgefilipecosta

jorgefilipecosta Aug 29, 2018

Member

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