Skip to content

Instantly share code, notes, and snippets.

@ylastapis
Created June 29, 2016 15:55
Show Gist options
  • Save ylastapis/2462502f0cd58855f0c94a3f754e7369 to your computer and use it in GitHub Desktop.
Save ylastapis/2462502f0cd58855f0c94a3f754e7369 to your computer and use it in GitHub Desktop.
Extend Sylius StaticContent model
<!--file: src/AppBundle/Resources/rdf-mappings/AppBundle.Document.StaticContent.xml-->
<type
xmlns:schema="http://schema.org/"
typeof="schema:WebPage"
>
<children>
<property property="schema:headline" identifier="title" tag-name="h1"/>
<property property="schema:text" identifier="body" />
<property property="schema:text" identifier="group" />
</children>
</type>
sylius_content:
driver: doctrine/phpcr-odm
resources:
static_content:
classes:
model: AppBundle\Document\StaticContent
# Access to this resource through API
app_api_static_content:
resource: |
alias: sylius.static_content
only: ['show', 'index']
type: sylius.resource_api
{#file: /app/Resources/SyliusWebBundle/views/Frontend/StaticContent/show.html.twig #}
{% extends 'SyliusWebBundle:Frontend:layout.html.twig' %}
{% if cmfMainContent is not defined %}
{% set cmfMainContent = static_content %}
{% endif %}
{% block content %}
{% createphp cmfMainContent as='rdf' noautotag %}
<div {{ createphp_attributes(rdf) }}>
<div class="page-header">
<h1 class="page-title" {{ createphp_attributes(rdf.title) }}>{{ createphp_content(rdf.title) }}</h1>
{#Add here my new attribute#}
<h1 class="page-group" {{ createphp_attributes(rdf.group) }}>{{ createphp_content(rdf.group) }}</h1>
</div>
<div {{ createphp_attributes(rdf.body) }}>{{ createphp_content(rdf.body) }}</div>
</div>
{% endcreatephp %}
{% endblock %}
<?php
// file: /src/AppBundle/Document/StaticContent.php
namespace AppBundle\Document;
use Sylius\Bundle\ContentBundle\Document\StaticContent as BaseStaticContent;
class StaticContent extends BaseStaticContent
{
/**
* PHPCR document group.
*
* @var string
*/
protected $group;
/**
* @return string
*/
public function getGroup()
{
return $this->group;
}
/**
* @param string $group
*/
public function setGroup($group)
{
$this->group = $group;
}
}
<!-- file: /src/AppBundle/Resources/config/doctrine/StaticContent.phpcr.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping
https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd"
>
<document name="AppBundle\Document\StaticContent" referenceable="true" translator="attribute" >
<field name="group" type="string" translated="false" nullable="true" />
</document>
</doctrine-mapping>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment