4. Project
How to migrate the rest of your project to Mayd 2. Migrating your projects code will be the biggest part of work. A possible approach is to migrate component by component.
There are some breaking changes in Mayd 2. These changes and their migration strategies are explained below.
Page Types
-
The function
getContentEntityClasswas replaced by a newcreateContentEntity. The new function does not longer return thestringname of your entity, but a new instance of it:Old:
public function getContentEntityClass () : string { return BlocksContent::class; }New:
public function createContentEntity () : Content { return new BlocksContent(); } - The
PageTypeclass no longer provides acopyContentmethod. Please remove it completely. - The
PageTypeclass no longer provides agetConfigmethod. Please remove it completely.
Block Types
-
The method
getBlockTypeClassis replaced by a new methodcreateEntity:Old:
public function getBlockTypeClass () : string { return Block::class; }New:
public function createEntity () : Block { return new Block(); } -
The method
getBlockFormTypeis replaced by a new methodgetFormType:Old:
public function getBlockFormType () : ?string { return BlockForm::class; }New:
public function getFormType () : string { return BlockForm::class; } -
The method
getAdminCardDetailsis replaced bygetSlotEntryData:Old:
public function getAdminCardDetails (Block $block) : ?string { return "<p>Description</p>"; }New:
public function getSlotEntryData (Block $block) : ?SlotEntryData { return new SlotEntryData("Description"); }You can use
DeferredTranslationof theRadBundleto translate contents of yourSlotEntryData:public function getSlotEntryData (Block $block) : ?SlotEntryData { return new SlotEntryData(new DeferredTranslation( "block-type.block.description.label", [] "backend" )); } - The method
getBlockContainerCssClassesis removed. You can add a wrappingdiv-Tag with that class attribute around your block template. -
The method
getAdditionalEditActionsis changed togetEditActions. You do not have to create a route for your crud manager anymore. There is a built-in action class that opens a crud-manager:Old:
public function getAdditionalEditActions () : array { return [ new EditAction("route.name", "icon", "translation.label"), ]; }New:
public function getEditActions (Block $block) : array { return [ new CrudBlockEditAction( "translation.label", "translation.crud.modal_headline", EntryCrudManager::CRUD_KEY, "translation.crud.headline", ["block" => $block] ), ]; } - The function
copyBlockDatais removed completely, as the commandmayd:pages:copy-pagehas been removed.
CRUD Manager
- Your crud managers have to implement the new
CrudManagerInterface. - The
CrudManagerInterfacenow just has four methods:getKey,configure,normalizeEntity, andgetModel. -
The model returned from
getModelhas to implement theCrudModelInterface.There is also a more specific
SortableCrudModelInterfaceinterface. Make sure to override the methodsaddandremove. And update the sort order within your new definition.
Entities
- Entities with a
slugcan use the@Slugvalidation fromMayd. You can remove your old custom validator. Do not forget to add a@UniqueEntity(fields={"slug", ...})annotation to the root of your entity. - All entities should implement RAD’s
EntityInterface.
Content
- The
Contentclass implementation changed: it does no longer allow the$pageto be passed in the constructor. You just have to remove it completely. - The
Contentclass already uses theRadTraits\IdTraitand theRadTraits\TimestampsTrait. Your entity does not need to implement them themselves. - The
Contentclass already implements theEntityInterface. Your entity does not need to implement it themselves. - The
Contentclass requires your implementation to provide agetAllSlotsfunction that returns an array of slots. If your page does not have any, just return an empty array.
Slot
- The constructor of your
Slotdoes no longer need the parameterstring $type. Please remove it completely. - The
Slotclass requires the implementation of agetContextmethod. - The
Slotclass no longer requires the implementation of agetPagemethod. Please remove it completely. You should however add it to theContentContextinYourSlot::getContext().
Block
- The constructor of your
Blockdoes no longer need the parameterSlot $slot. Please remove it completely. - If your block implements a
__clone()method, make sure to call the parentparent::__clone();method in it.
If your block contains attached relations (like block entries), your block model should implement the EventSubscriberInterface and listen to the BlockRemoveEvent, to also mark the attached relations for removal.
Block Entries
- All block entries should now implement the
BlockEntryInterface.
Models
- All models should now extend the
Modelbase class from the RAD Bundle.
The models don’t flush automatically in the ->add(), ->update() and ->remove() methods anymore. Instead you must explicitly call ->flush() from the outside.
It’s always the responsibility of the top most component (typically Controller or Command) to flush. Use this pattern:
$model->update($entity)->flush();The model itself should never flush internally.
Controller
Page
-
The parameters
Page $page, AbcBlocksContent $contentare no longer directly provided. Instead aPageRequestContext $contextis provided. This context contains thepageand thecontent. You can render your template like this:public function index (PageRequestContext $context) : Response { return $this->render("index.html.twig", $context->mergeParameters([ "currentLocale" => $context->getLocale(), "website" => $context->getWebsite(), ])); }By using the
mergeParametersmethod,context,page, andcontentare automatically passed to your template.You can then include the context in your base layout (e.g.
layout.html.twig)... {#- @var \Mayd\Pages\Request\RequestContext context|null -#} {%- set context = context ?? null -%} ... - The
render_slottwig function now requires thecontextas second parameter.
Forms
- Mayd provides a built in
RichTextType.
RTE
- If your project uses the old RTE, that stores data as
mobiledoc, you have to migrate your data tohtml, as the new RTE stores its data ashtml. - The RTE provides a built-in twig function
rich_text, that replaces previousrender_content()implementations.
Frontend Templates
-
You need to implement one or more
FrondendThemes. These define the required assets, body classes and available menu locations.class ProjectNameTheme extends FrontendTheme { /** * @inheritDoc */ public function getHeaderAssets () : array { return [ "@app/css/projectName.css", ]; } /** * @inheritDoc */ public function getFooterAssets () : array { return [ "@app/js/projectName.js", ]; } /** * @inheritDoc */ public function getBodyClass () : ?string { return "projectName"; } public function getMenuLocations () : array { return [ new MenuLocation("footer"), new MenuLocation("service"), ]; } } -
The use of these Templates is important, especially in connection with the change in the structure of your root twig template (extension of
@MaydCore/frontend.html.twig, described in section Twig Templates.Make sure to select the theme for every application. You can configure that in the application backend.
Twig Templates
- Your frontend root template should extend the
@MaydCore/frontend.html.twigtemplate:
{%- extends "@MaydCore/frontend.html.twig" -%}Please be aware that the usage of that template may change some of your block definitions. E.g. tracking_head would move to assets_head
Blocktemplates moved fromtemplates/blockstotemplates/block.- The
render_slottwig function now requires thecontextas second parameter. - The namespace
@buildmay have changed to@appdepending on your configuration. - The path to your main assets (
##.jsand##.css) may have changed, depending on your kaba configuration. -
The function
file_preview_urlis replaced byimage_url. The new function requires a image size. This size is configured inconfig/packages/mayd.yaml:mayd_files: image_sizes: slider: width: 844 height: 720 # optional mode: cover # optional (contain / cover) content: width: 844
Translations
-
Mayd 2 uses the
intl-icutranslation format. This entails several syntax changes, for example:- Placeholders are no longer formated as
%placeholder%but now as:{placeholder} transChoiceis now gone and is transparently natively supported in regular translation keys with->trans().
- Placeholders are no longer formated as
- Translation keys (especially those generated by Mayd e.g. for
page-types) are now written inkebab-case.
Configuration
- If your project has a
config/packages/twig.yamlandexception_controllerdefined in it, you need to remove it. This is replaced by a mayd built-in controller and now defined inconfig/packages/framework.yaml config/packages/gluggi_bundle.yamlis nowconfig/packages/gluggi.yamland may require some changes, as you may have a new asset target file structure.