我已经创建了一个安装脚本,用于通过Magento2中的bluefoot模块创建内容块。请找到我使用的以下代码:
app / code / Tryzens / Extendbluefoot / etc / bluefoot / pagebuilder.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:gene:bluefoot:etc/bluefoot/pagebuilder.xsd">
<content_blocks>
<templates>
<template name="zimmermann_image"
file="Tryzens_Extendbluefoot::image.phtml"/>
</templates>
<renderers>
<renderer name="zimmermann_image_renderer"
class="Tryzens\Extendbluefoot\Block\ImageBlock"/>
</renderers>
</content_blocks>
</config>
app / code / Tryzens / Extendbluefoot / Setup / InstallData.php
<?php
namespace Tryzens\Extendbluefoot\Setup;
use Gene\BlueFoot\Api\ContentBlockGroupRepositoryInterface;
use Gene\BlueFoot\Api\Data\ContentBlockGroupInterface;
use Gene\BlueFoot\Api\Data\ContentBlockGroupInterfaceFactory;
use Gene\BlueFoot\Model\Installer\File as InstallerFile;
use Magento\Framework\Filesystem\Io\File as IoFile;
use Magento\Framework\Module\Dir\Reader;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* Class to install data for list builder BlueFoot block
*/
class InstallData implements InstallDataInterface
{
/**
* @var ContentBlockGroupInterfaceFactory
*/
protected $contentBlockGroupInterfaceFactory;
/**
* @var ContentBlockGroupRepositoryInterface
*/
protected $contentBlockGroupRepository;
/**
* @var Reader
*/
protected $moduleReader;
/**
* @var IoFile
*/
protected $ioFile;
/**
* @var InstallerFile
*/
protected $fileInstaller;
/**
* InstallData constructor.
*
* @param ContentBlockGroupInterfaceFactory $contentBlockGroupInterfaceFactory
* @param ContentBlockGroupRepositoryInterface $contentBlockGroupRepositoryInterface
* @param Reader $moduleReader
* @param IoFile $ioFile
* @param InstallerFile $fileInstaller
*/
public function __construct(
ContentBlockGroupInterfaceFactory $contentBlockGroupInterfaceFactory,
ContentBlockGroupRepositoryInterface $contentBlockGroupRepositoryInterface,
Reader $moduleReader,
IoFile $ioFile,
InstallerFile $fileInstaller
) {
$this->contentBlockGroupInterfaceFactory = $contentBlockGroupInterfaceFactory;
$this->contentBlockGroupRepository = $contentBlockGroupRepositoryInterface;
$this->moduleReader = $moduleReader;
$this->ioFile = $ioFile;
$this->fileInstaller = $fileInstaller;
}
/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$this->addContentBlockGroup();
$this->installData($setup);
$setup->endSetup();
}
/**
* Add zimmermann content block group (menu section)
*/
protected function addContentBlockGroup()
{
/** @var ContentBlockGroupInterface $group */
$group = $this->contentBlockGroupInterfaceFactory->create();
$group->setCode('zimmermann')
->setName('Zimmermann')
->setIcon('<i class="fa fa-picture-o"></i>')
->setSortOrder('55');
$this->contentBlockGroupRepository->save($group);
}
/**
* Install list page builder blocks and attributes from specified JSON file
*
* @param ModuleDataSetupInterface $setup
*/
protected function installData(ModuleDataSetupInterface $setup)
{
$file = $this->moduleReader->getModuleDir(false, 'Tryzens_Extendbluefoot') . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'install-blocks-attributes.json';
if ($this->ioFile->fileExists($file)) {
$this->fileInstaller->install($file, $setup);
}
}
}
app / code / Tryzens / Extendbluefoot / Setup / data / install-blocks-attributes.json
{
"content_blocks": [
{
"identifier": "zimmermann_image",
"name": "Image",
"content_type": "block",
"description": "Image builder",
"url_key_prefix": null,
"preview_field": null,
"renderer": "zimmermann_image_renderer",
"item_view_template": "zimmermann_image",
"list_template": null,
"list_item_template": null,
"item_layout_update_xml": null,
"list_layout_update_xml": null,
"singular_name": "Image",
"plural_name": null,
"include_in_sitemap": "0",
"searchable": "0",
"icon_class": "fa fa-picture-o",
"color": "#5284bd",
"show_in_page_builder": "1",
"sort_order": "100",
"group": "zimmermann",
"attribute_data": {
"attributes": [
"z_title",
"z_image",
"z_mobile_image",
"z_alt_tag",
"z_destination_image",
"z_text_one",
"z_text_one_mobile",
"z_text_one_link",
"z_text_two",
"z_text_two_mobile",
"z_text_two_link",
"z_view_more_text",
"z_view_more_link"
],
"groups": [
{
"attribute_group_name": "Options",
"sort_order": "10",
"default_id": "0",
"attributes": [
{
"attribute_code": "z_title",
"sort_order": "10"
},
{
"attribute_code": "z_image",
"sort_order": "20"
},
{
"attribute_code": "z_mobile_image",
"sort_order": "30"
},
{
"attribute_code": "z_alt_tag",
"sort_order": "40"
},
{
"attribute_code": "z_destination_image",
"sort_order": "50"
},
{
"attribute_code": "z_text_one",
"sort_order": "60"
},
{
"attribute_code": "z_text_one_mobile",
"sort_order": "70"
},
{
"attribute_code": "z_text_one_link",
"sort_order": "80"
},
{
"attribute_code": "z_text_two",
"sort_order": "90"
},
{
"attribute_code": "z_text_two_mobile",
"sort_order": "100"
},
{
"attribute_code": "z_text_two_link",
"sort_order": "110"
},
{
"attribute_code": "z_view_more_text",
"sort_order": "120"
},
{
"attribute_code": "z_view_more_link",
"sort_order": "130"
}
]
}
]
}
}
],
"attributes": [
{
"attribute_code": "z_title",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["Image Title"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_image",
"attribute_model": null,
"backend_model": "gene_bluefoot\/attribute_backend_image",
"backend_type": "text",
"backend_table": null,
"frontend_model": null,
"frontend_input": "image",
"frontend_label": ["Desktop Image"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_mobile_image",
"attribute_model": null,
"backend_model": "gene_bluefoot\/attribute_backend_image",
"backend_type": "text",
"backend_table": null,
"frontend_model": null,
"frontend_input": "image",
"frontend_label": ["Mobile Image"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_alt_tag",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["Image Alt"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_destination_image",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["Destination Image Link"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_text_one",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["Text1"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_text_one_mobile",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["Text1 Mobile"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_text_one_link",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["Text1 Link"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_text_two",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["Text2"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_text_two_mobile",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["Text2 Mobile"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_text_two_link",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["Text2 Link"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_view_more_text",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["View More Text"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
},
{
"attribute_code": "z_view_more_link",
"attribute_model": null,
"backend_model": null,
"backend_type": "varchar",
"backend_table": null,
"frontend_model": null,
"frontend_input": "text",
"frontend_label": ["View More Link"],
"frontend_class": null,
"source_model": null,
"is_required": "0",
"is_user_defined": "1",
"is_unique": "0",
"note": null,
"is_global": "0",
"is_wysiwyg_enabled": "0",
"is_visible": "1",
"content_scope": "0",
"frontend_input_renderer": null,
"widget": null,
"data_model": null,
"template": null,
"list_template": null,
"additional_data": [],
"entity_allowed_block_type": false
}
]
}
但是在执行
时php bin/magento setup:upgrade
我收到错误发现唯一约束违反
答案 0 :(得分:0)
Atlast得到了答案。 只需更改
“名称”:“图片”,
其他。因为图像已经创建。