A talk covering how developers can add new content to BlueFoot CMS in Magento 2. More details available at: http://www.magetitans.it/discovering-bluefoot-john-hughes/
2. @JohnHughes1984
ABOUT ME
•Technical Director at Fisheye
•Working with Magento ≈ 5 years
•Passionate about:
- Ensuring developers have tools / guidance
to work efficiently and follow best practice
- Providing best in class solutions for
merchants
- Being part of #RealMagento community
IMAGINE 2017
MOST INNOVATIVE
WEBSITE
AWARD WINNERS
3. @JohnHughes1984
OVERVIEW
•What is BlueFoot?
•Developer overview of ‘Page Builder Blocks’
•Creating a module to add BlueFoot ‘Page Builder Blocks’
•Ideas for new content types and further customisation
•What the future holds for BlueFoot
5. @JohnHughes1984
LET’S HAVE A SHOW OF HANDS 🙌
•Who knows what BlueFoot is?
•Who’s installed it or used it in a project?
•Who’s extended it?
6.
7. •CMS & Page Builder for Magento
- Built by Gene Commerce
- Acquired by Magento in December 2015
•Drag & drop multiple content types in flexible row / column layouts
•Can be used anywhere in admin where WYSIWYG area is present
16. @JohnHughes1984
BLUEFOOT ENTITY TYPE
• Not to be confused with standard
entity types
• BlueFoot Entity Type =
Page Builder Block
- e.g. Image, Video, Slider
• ‘gene_bluefoot_entity_type’ table
17. @JohnHughes1984
BLUEFOOT ENTITY TYPE GROUP
• BlueFoot Entity Types are assigned
to a ‘BlueFoot Entity Type Group’
- Menu group headings
- e.g. General, Media, Commerce
- ‘gene_bluefoot_entity_type_group’
table
19. @JohnHughes1984
ATTRIBUTE SETS
•All attributes can be added to an attribute set just like any other
EAV type
•Each ‘BlueFoot Entity Type’ (‘Page Builder Block’) is linked to a
unique attribute set of the same name
- e.g. the ‘Driver’ Page Builder Block has an accompanying
attribute set also named ‘Driver’ to store its attributes
20. @JohnHughes1984
ATTRIBUTE GROUPS
• Each ‘Page Builder Blocks’
attribute set can be further split
into groups
• These groups map to tabs within
‘Page Builder Block’ edit panel
- e.g. Images, Link, Seo, Advanced
23. @JohnHughes1984
PAGE BUILDER BLOCK
•When it comes to rendering each ‘Page Builder Block’ is assigned a block
class and template file
•‘Page Builder Blocks’ can also have child items
- e.g. individual banners within a slider / carousel or items within an
accordion
- These child items are also ‘Page Builder Blocks’ (BlueFoot Entity Types)
but are generally hidden from the menu
24. @JohnHughes1984
ADDING NEW CONTENT
•BlueFoot allows creation / management of attributes sets (‘Page
Builder Blocks’) within the admin panel
•Block classes, templates & other settings can also be managed
•This is great… but for reusable solutions we need to build a
module
26. @JohnHughes1984
LIST BUILDER
Let’s create a list builder, made up of:
• A ‘List’ Page Builder Block - for <ul>
elements
• A child ‘List Items’ block - for <li>
elements
• A new ‘Fisheye’ group to display our
block under in BlueFoot menu
27. @JohnHughes1984
LIST PAGE BUILDER BLOCK
• Options
- List Title - text field
- List Style - select - e.g. none, circle, disc etc.
• Items
- List Items - child_item - for List Item blocks
• Advanced
- CSS Classes - default attribute for CSS
28. @JohnHughes1984
LIST ITEM PAGE BUILDER BLOCK
• Options
- List Text - text field
- List Icon - text field - Font Awesome
• Link
- List Link URL - text field
- Link Target - boolean
• Advanced
- CSS Classes - default attribute for CSS
29. @JohnHughes1984
MODULE COMPONENTS
• General module configuration files
• BlueFoot specific configuration files
• Install script and data source(s)
• View files - block classes and templates
• Static assets - CSS, JS, images etc.
30. @JohnHughes1984
GENERAL MODULE CONFIGURATION
As with any other module we’ll need the basics:
•composer.json - declare dependency on gene/bluefoot package
•etc/module.xml - add Gene_BlueFoot to sequence node ensure correct load
order
•registration.php - registers module
31. @JohnHughes1984
BLUEFOOT SPECIFIC CONFIGURATION
BlueFoot has its own XML/XSD configuration files:
•Renderers - block classes for use by Page Builder Blocks
•Templates - template files for for use by Page Builder Blocks
•Plugins - JS widgets e.g. colour picker, product search, maps
•Structural elements - e.g. rows and columns
33. @JohnHughes1984
INSTALL SCRIPT
•In essence the same as any other installer script
•To create new entity type group we need to inject
GeneBlueFootApiContentBlockGroupRepositoryInterface and
GeneBlueFootApiDataContentBlockGroupInterface
•Injecting GeneBlueFootModelInstallerFile we can import data
from JSON file rather than MagentoEavSetupEavSetup methods
34. @JohnHughes1984
Setup/InstallData.php
class InstallData implements InstallDataInterface
{
/** … */
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$setup->startSetup();
$this->addContentBlockGroup();
$this->installData($setup);
$setup->endSetup();
}
41. @JohnHughes1984
Setup/data/install-blocks-attributes.json
"attributes": [
{
"attribute_code": "list_style",
"backend_model": null,
"backend_type": "varchar",
"frontend_input": "select",
"frontend_label": ["List Style"],
"source_model": "FisheyeBlueFootListModelEntityAttributeSourceListStyle",
"is_required": "1",
"is_user_defined": "1",
"note": null,
"is_visible": "1",
"widget": null,
"data_model": null,
"entity_allowed_block_type": false
…
},
…
]
CUSTOM SOURCE MODEL
NEVER SET TO “0” AS WILL
ADD ATTRIBUTE TO ALL
ATTRIBUTES SETS!!!
FOR ADDING NEW ATTRIBUTES
42. @JohnHughes1984
Setup/data/install-blocks-attributes.json
"attributes": [
{
"attribute_code": "list_items",
"backend_model": "MagentoEavModelEntityAttributeBackend
ArrayBackend",
"backend_type": "text",
"frontend_input": "child_entity",
"frontend_label": ["List Items"],
"source_model": "GeneBlueFootModelAttributeSourceEntity
Child",
"entity_allowed_block_type": “fisheye_list_item”,
…
},
…
]
BACKEND & SOURCE
MODEL REQUIRED FOR
CHILD BLOCK ATTRIBUTES
ENSURES ATTRIBUTE IS
ONLY USED FOR THE
SPECIFIED BLOCK TYPE
43. @JohnHughes1984
VIEW FILES
•Block classes / template files need to be placed as declared in
etc/bluefoot/pagebuilder.xml earlier
•Blocks extend GeneBlueFootBlockEntityPageBuilderBlockAbstractBlock
•Admin templates use mustache.js templates
- {{attribute_code}} handles are replaced via JS to update preview
44. @JohnHughes1984
Block/ListBlock.php
class ListBlock extends AbstractBlock
{
/** … */
public function getListTitle()
{
return $this->stripTags($this->getEntity()->getData('list_title'));
}
/** … */
public function getListStyle()
{
return $this->getEntity()->getData('list_style');
}
}
45. @JohnHughes1984
Block/ListItem.php
class ListItem extends AbstractBlock
{
/** … */
public function getItemIcon()
{
return $this->stripTags($this->getEntity()->getData('list_item_icon'));
}
/** … */
public function getItemLinkUrl()
{
return $this->escapeXssInUrl($this->getEntity()-
>getData('list_item_url'));
}
…
57. @JohnHughes1984
FURTHER POSSIBILITIES
•Menu builder
•Form builder
•Magento elements (e.g. advanced search, quick order)
•Social media feeds (e.g. Twitter / Facebook / Instagram)
•Content from other systems (e.g. WordPress posts via WP API)
58. @JohnHughes1984
FURTHER POSSIBILITIES CONT.
•Add new attribute types with rich content via plugins (JS widgets)
- Default widgets include:
• Colour picker, Google maps, video preview and entity search
e.g. products and categories
•New structural elements
59. @JohnHughes1984
FISHEYE USAGE
•At Fisheye we’ve built our entire frontend around BlueFoot
- Page Builder Blocks - banners, trust, social and more
- Plugins (JS widgets) - CMS page search
- Wrapped into our own CMS framework
60. @JohnHughes1984
–Phillip Jackson, speaking during MageTalk Live at Magento Imagine 2017
“BLUEFOOT HAS GIVEN US A
‘LEG UP’ TO SELL MAGENTO 2 IN
A BIGGER AND BROADER WAY”
62. @JohnHughes1984
WHERE NEXT FOR BLUEFOOT?
•Fully integrated in Magento v2.3 as ‘Magento Advanced CMS’
- Expected late 2017…
•Majority of functionality will be for ‘Enterprise Edition only’
•Core version integrated into Magento UI with native drag & drop
•Integration of Adobe CC image editing
63. @JohnHughes1984
THANK YOU FOR LISTENING! 👏
Want to know more / see a demo? Come say hi 💬🍻 or get in touch:
•Twitter: @JohnHughes1984
•Email: johnh@fisheyehq.com
•LinkedIn: linkedin.com/in/johnhughes1984
64. @JohnHughes1984
Q&A
•Will this example / way of extending be relevant once 2.3 released?
- Unsure, better directed at Magento core team
- At very least vendor and namespaces will change and given the plans to refactor natively there
are bound to be further changes required, but confident most of concepts will remain similar and
hopefully porting extensions shouldn’t be too large a task (not exactly large modules)
•How do I get BlueFoot?
- Using composer (requires Enterprise Edition access keys) - composer require gene/bluefoot
- Download via partner portal