How to import(via csv) custom field(placeholder) in custom CMS Block?

matej
matej Posts: 9 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

i have created a custom CMS Block and inside it placeholder named "image".
In cms_block.csv there is no such placeholder in csv header, but if i add it and properly enter data it is not stored in db after running import.

Is is possible to import custom placeholder via csv?
and tutorial or documentation on that tomic?

Best Answer

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,051 โš–๏ธ - Guardians (admin)
    Answer โœ“

    Heyhey,

    I have never done this by myself yet but let me try to help you find a solution by yourself.

    First we need to understand which importer we use. Look in which import yml file the cms_block.csv is linked so you get the data-type: so open for example data/import/local/full_EU.yml and you will see:

    - data_entity: cms-block
    source: data/import/common/common/cms_block.csv

    Now lets do a full text search in src/Pyz/Zed/DataImport for the data_entity "cms-block". We will find the constant IMPORT_TYPE_CMS_BLOCK in src/Pyz/Zed/DataImport/DataImportConfig.php.

    Lets do another search in that same module for that constant and we will find an usage in src/Pyz/Zed/DataImport/Business/DataImportBusinessFactory.php and the matching createCmsBlockImporter() method.

    Have a look at that method and focus on the following part:

    $dataSetStepBroker->addStep($this->createAddLocalesStep())
    ->addStep($this->createLocalizedAttributesExtractorStep([
    CmsBlockWriterStep::KEY_PLACEHOLDER_TITLE, CmsBlockWriterStep::KEY_PLACEHOLDER_CONTENT, CmsBlockWriterStep::KEY_PLACEHOLDER_LINK, CmsBlockWriterStep::KEY_PLACEHOLDER_IMAGE_URL, ]))
    ->addStep(new CmsBlockWriterStep());

    This gives us already an idea which Step we have to analyze. createLocalizedAttributesExtractorStep() which instantiates vendor/spryker/data-import/src/Spryker/Zed/DataImport/Business/Model/DataImportStep/LocalizedAttributesExtractorStep.php. Looking into that step we see there is not much additional logic. So we will have to go back to the method createCmsBlockImporter() in src/Pyz/Zed/DataImport/Business/DataImportBusinessFactory.php and just add our new placeholder there as well.

    Not sure if sth is missing there but this should hopefully lead you to the rightsolution :)

    All the best,

    Florian

Answers

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,051 โš–๏ธ - Guardians (admin)
    Answer โœ“

    Heyhey,

    I have never done this by myself yet but let me try to help you find a solution by yourself.

    First we need to understand which importer we use. Look in which import yml file the cms_block.csv is linked so you get the data-type: so open for example data/import/local/full_EU.yml and you will see:

    - data_entity: cms-block
    source: data/import/common/common/cms_block.csv

    Now lets do a full text search in src/Pyz/Zed/DataImport for the data_entity "cms-block". We will find the constant IMPORT_TYPE_CMS_BLOCK in src/Pyz/Zed/DataImport/DataImportConfig.php.

    Lets do another search in that same module for that constant and we will find an usage in src/Pyz/Zed/DataImport/Business/DataImportBusinessFactory.php and the matching createCmsBlockImporter() method.

    Have a look at that method and focus on the following part:

    $dataSetStepBroker->addStep($this->createAddLocalesStep())
    ->addStep($this->createLocalizedAttributesExtractorStep([
    CmsBlockWriterStep::KEY_PLACEHOLDER_TITLE, CmsBlockWriterStep::KEY_PLACEHOLDER_CONTENT, CmsBlockWriterStep::KEY_PLACEHOLDER_LINK, CmsBlockWriterStep::KEY_PLACEHOLDER_IMAGE_URL, ]))
    ->addStep(new CmsBlockWriterStep());

    This gives us already an idea which Step we have to analyze. createLocalizedAttributesExtractorStep() which instantiates vendor/spryker/data-import/src/Spryker/Zed/DataImport/Business/Model/DataImportStep/LocalizedAttributesExtractorStep.php. Looking into that step we see there is not much additional logic. So we will have to go back to the method createCmsBlockImporter() in src/Pyz/Zed/DataImport/Business/DataImportBusinessFactory.php and just add our new placeholder there as well.

    Not sure if sth is missing there but this should hopefully lead you to the rightsolution :)

    All the best,

    Florian

  • matej
    matej Posts: 9 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Thank you.
    Works perfectly