Importing
Intro
To import an article:
<?php
$pageManager = $this->container->get('wf_cms.page_manager'); //obviously, you may have to adapt this line in order to get the wf_cms.page_manager service
$page = $this->pageManager->getNewPageArticle();
$page->setTitle('title of the page');
$entityManager->persist($page);
$entityManager->flush();
It's important to use the wf_cms.page_manager
service to get a new instance of the PageArticle object, as it injects some dependencies into it. Otherwise, you get an error:
PHP Fatal error: Call to a member function create() on a non-object in
/[...]/vendor/wfcms/cms-base-bundle/Wf/Bundle/CmsBaseBundle/Entity/Page.php on line [...]
Custom fields and module roles
The (default) article's template defines some modules with roles:
'wfed/title/page_title': {
role: 'title'
}
For now, only the default article's template is used for importing articles.
Here's a list of built-in roles:
title
: the titlesupra
: the line above the titleepigraph
: the introductory paragraph (short description)signature
: the field containing the signature (editor's name, agency)location
: the location (if available) where the news happenedimage
: the main image of the article. The image chosen in this module is used to auto-populate the image modules of page captioned modules when this article is selected in a boardimage_captioned
: use this instead of theimage
if the main image has a captionparagraph
: use this for the normal paragraph (body text)
You can also define a custom role name:
'wfed/body_text/inline': {
role: 'cargo'
}
After that you can call directly:
<?php
$page->setCargo('New cargo field will be displayed in the template');
After making changes to template's roles (change the module ID or module's options/className/tagName/etc.) these changes must be converted from JavaScript to the JSON stored in app/config/cms/templates/default.json
. PageEditorModuleCollection
uses this JSON data to set modules and show these fields in the HTML of the imported article.
make wf-templates-config
task does this conversion. It requires PhantomJS to execute the script, so make sure you have it installed. On success you should get the message got callback template-config
and the default.json should be updated with the correct values. On error, open the URL mentioned by the command (http://PROJECT_ADMIN_URL/export/editor/template_config_dump) and check the console for js errors.
Using Xalok docs importer bundle
There are two parameters that need to be configured (app/config/parameters/project.yml
is a good place to put these parameters):
First, the article_field_map, it maps fields in PageArticle to values in the XML.
xalok_docs.article_field_map:
sourceId: //data/id
title: //data/titular
paragraphs: //data/cuerpo
category: //metadata/cuerpo
tags: //metadata/tags
publishedAt: //metadata/publishedDate
pageSlugs: //metadata/pageSlugs
attachments:
type: array
xdocs_path: //related/attachment
field_map:
id: //id
url: //url
type: //type
title: //metadata/file_description
Second, the category_map, it maps categories found in the XML to categories in WfCMS:
xalok_docs.category_map:
"Noticias": "Actualidad"
"Agromar": "Actualidad"
Use the command ./app/admin/console wf:cms:xalokdocs:import
to start importing the XMLs found in __PROJECT_DIR__/app/XdocsXml
. This command deletes the XMLs after processing them, to avoid processing the same XML twice.
While developing this command takes a --demo-xmls
option (or the shorthand version -d
(./app/admin/console wf:cms:xalokdocs:import -d
). When running the command with this option, it does two things:
- first, it changes the directory where it looks for XMLs to
__PROJECT_DIR__/app/XdocsXmlDemo
- second, it doesn't delete the XMLs after running, so you don't have to copy the same XMLs over and over again while testing 😄
Asking for help
If help is needed with the Xalok docs importation, create a separate branch in the project, add the XMLs in app/XdocsXmlDemo
(it's not ignored by git) and push these files together with your changes. Then, emailing the name of the project and the name of the branch should be enough (together with a description of the issue, of course 😃 )!