I am trying to overwrite the following bluefoot content block found in vendor/gene/bluefoot/model/setup/data/pagebuilder_blocks_core.json
{ "identifier": "button_item", "name": "Button", "content_type": "block", "description": "Single Button", "url_key_prefix": null, "preview_field": "link_text", "renderer": "core_default", "item_view_template": "core_button_item", "list_template": null, "list_item_template": null, "item_layout_update_xml": null, "list_layout_update_xml": null, "singular_name": "Button", "plural_name": null, "include_in_sitemap": "0", "searchable": "0", "icon_class": "fa fa-mouse-pointer", "color": "#5284bd", "show_in_page_builder": "0", "sort_order": "0", "group": "general", "attribute_data": { "attributes": [ "link_text", "link_url", "css_classes" ], "groups": [ { "attribute_group_name": "General", "sort_order": "1", "default_id": "0", "attributes": [ { "attribute_code": "link_text", "sort_order": "1" }, { "attribute_code": "link_url", "sort_order": "2" } ] }, { "attribute_group_name": "Advanced", "sort_order": "2", "default_id": "0", "attributes": [ { "attribute_code": "css_classes", "sort_order": "1" } ] } ] } }
Here is the new json I am trying to add to the db durin install of my module.
{ "content_blocks": [ { "identifier": "button_item", "name": "Button", "content_type": "block", "description": "Single Button", "url_key_prefix": null, "preview_field": "link_text", "renderer": "core_default", "item_view_template": "core_button_item", "list_template": null, "list_item_template": null, "item_layout_update_xml": null, "list_layout_update_xml": null, "singular_name": "Button", "plural_name": null, "include_in_sitemap": "0", "searchable": "0", "icon_class": "fa fa-mouse-pointer", "color": "#A55A55", "show_in_page_builder": "0", "sort_order": "0", "group": "general", "attribute_data": { "attributes": [ "link_text", "link_url", "button_type", "css_classes" ], "groups": [ { "c": "General", "sort_order": "1", "default_id": "0", "attributes": [ { "attribute_code": "link_text", "sort_order": "1" }, { "attribute_code": "link_url", "sort_order": "2" }, { "attribute_code": "button_type", "sort_order": "3" } ] }, { "attribute_group_name": "Advanced", "sort_order": "2", "default_id": "0", "attributes": [ { "attribute_code": "css_classes", "sort_order": "1" } ] } ] } } ], "attributes": [ { "attribute_code": "button_type", "attribute_model": null, "backend_model": null, "backend_type": "varchar", "backend_table": null, "frontend_model": null, "frontend_input": "select", "frontend_label": ["Button Type"], "frontend_class": null, "source_model": "eav\/entity_attribute_source_table", "is_required": "1", "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, "option": { "value": { "option_0": ["primary"], "option_1": ["secondary"], "option_2": ["alt"], "option_3": ["action"] }, "order": { "option_0": "", "option_1": "", "option_2": "", "option_3": "" }, "delete": { "option_0": "", "option_1": "", "option_2": "", "option_3": "" } } } ] }
The new “button_type” is being inserted into the db correctly, but the json that I want to overwrite the “button_item” is not working.
I have this install script where I am installing this json file, and I believe I need to delete the old “button_item” content block from the db first in order for the new one to work. Here is the install script.
app/code/Vendor/Module/Setup/InstallData.php <?php namespace vendor\module\Setup; use Gene\BlueFoot\Model\Attribute\ContentBlock as ContentBlock; use Gene\BlueFoot\Model\Attribute\ContentBlockRepository; 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 Reader */ protected $ moduleReader; /** * @var IoFile */ protected $ ioFile; /** * @var InstallerFile */ protected $ fileInstaller; /** * @var Bluefoot content block repository manager */ protected $ contentBlockRepository; /** * @var */ protected $ attributeFactory; protected $ contentBlockInterface; /** * InstallData constructor. * * @param Reader $ moduleReader * @param IoFile $ ioFile * @param InstallerFile $ fileInstaller */ public function __construct( Reader $ moduleReader, IoFile $ ioFile, InstallerFile $ fileInstaller, ContentBlockRepository $ contentBlockRepository ) { $ this->moduleReader = $ moduleReader; $ this->ioFile = $ ioFile; $ this->fileInstaller = $ fileInstaller; $ this->contentBlockRepository = $ contentBlockRepository; } /** * Installs data for a module * * @param ModuleDataSetupInterface $ setup * @param ModuleContextInterface $ context */ public function install(ModuleDataSetupInterface $ setup, ModuleContextInterface $ context) { $ setup->startSetup(); $ buttonItemBlock = $ this->contentBlockRepository->getByIdentifier('button_item'); $ this->contentBlockRepository->delete($ buttonItemBlock); //Install the blocks and attributes $ this->installData($ setup); $ setup->endSetup(); } /** * Install blocks and attributes from specified JSON file * * @param ModuleDataSetupInterface $ setup */ protected function installData(ModuleDataSetupInterface $ setup) { $ file = $ this->moduleReader->getModuleDir(false, 'Vendor_Module') . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'install-blocks-attributes.json'; if ($ this->ioFile->fileExists($ file)) { $ this->fileInstaller->install($ file, $ setup); } } }
When I run this I get this error
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Gene\BlueFoot\Model\Attribute\ContentBlockRepository::delete() must be an instance of Gene\BlueFoot\Api\Data\ContentBlockInterface, instance of Gene\BlueFoot\Model\Attribute\ContentBlock\Interceptor given