Skip to content

Instantly share code, notes, and snippets.

@arfaram
Created July 3, 2019 09:57
Show Gist options
  • Save arfaram/8d9e6bf2ca0ebe40b24c8e169f5dd929 to your computer and use it in GitHub Desktop.
Save arfaram/8d9e6bf2ca0ebe40b24c8e169f5dd929 to your computer and use it in GitHub Desktop.
Custom ezstring FieldType edit Template for a given ContentType(artcile) in ezplatform 2.x - for demo purpose
<?php
namespace EzSystems\CustomizeAdminUIBundle\lib\Matcher\ContentBased\Identifier;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued;
use eZ\Publish\Core\MVC\Symfony\View\View;
class ContentTypeIdentifierForCreateView extends MultipleValued
{
public function matchLocation(Location $location)
{
return false;
}
public function matchContentInfo(ContentInfo $contentInfo)
{
return false;
}
public function match(View $view)
{
return isset($this->values[$view->getContentType()->identifier]);
}
}
{# choose the fieldtype widget to override by customizing the block 'ezplatform_fieldtype[fieldtype_identifier]_widget #}
{%- block ezplatform_fieldtype_ezstring_widget -%}
{# checking the field identifier #}
{% if form.parent.vars.name == 'title' %}
{# add your custom code here #}
{% if form.parent.vars.data.fieldDefinition.descriptions[form.parent.vars.languageCode] is defined %}
<small>
<i>
{{ form.parent.vars.data.fieldDefinition.descriptions[form.parent.vars.languageCode] }}
</i>
</small>
{% endif %}
{{- block('form_widget_simple') -}}
{{- block('description') -}}
{% else %}
{{- block('form_widget_simple') -}}
{% endif %}
{%- endblock -%}
{%- block description -%}
{#https://doc.ezplatform.com/en/latest/guidelines/components/modals/#}
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-modal-launcher" data-toggle="modal" data-target="#ez-modal--custom-url-alias"> Seo? <img src="https://ez.no/bundles/eznodesign/images/favicon.ico"></button>
<!-- Modal -->
<div class="modal fade ez-modal ez-translation show" id="ez-modal--custom-url-alias" tabindex="-1" role="dialog" aria-modal="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Title SEO</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<svg class="ez-icon ez-icon--medium" aria-hidden="true">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../../ez-icons.svg#discard"></use>
</svg>
</button>
</div>
<div class="modal-body">
<span class="ez-translation__title">Analyzing the keyword is the first step to making your post’s title SEO friendly</span>
</div>
<div class="modal-footer justify-content-center">
<button type="button" class="btn btn-primary" data-dismiss="modal">Thanks</button>
</div>
</div>
</div>
</div>
{%- endblock -%}
#be sure to create the template and Matcher folder structure or create your own and adapt the configuration
system:
admin_group:
#EDIT
content_edit_view:
full:
ezplatform_admin_ui_article:
template: '@ezdesign/content/content_edit/content_edit.html.twig'
match:
Identifier\ContentType: [article]
params:
viewbaseLayout: '@ezdesign/layout.html.twig'
form_templates: ["@ezdesign/fieldtypes/edit/ezstring.html.twig"]
#CREATE
content_create_view:
full:
ezplatform_admin_ui_article_create:
template: '@ezdesign/content/content_edit/content_create.html.twig'
match:
\EzSystems\CustomizeAdminUIBundle\lib\Matcher\ContentBased\Identifier\ContentTypeIdentifierForCreateView:
- article
params:
viewbaseLayout: '@ezdesign/layout.html.twig'
form_templates: ["@ezdesign/fieldtypes/edit/ezstring.html.twig"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment