Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions bundle/Core/FieldType/Metas/FormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data)
$formConfig = $fieldForm->getConfig();

$metasConfig = $this->configResolver->getParameter('fieldtype_metas', 'nova_ezseo');

if (empty($data->value->metas)) {
foreach (array_keys($metasConfig) as $key) {
$data->value->metas[$key] = new Meta($key, '');
}
$metasData = $data->value->metas;
foreach ($metasConfig as $key => $meta) {
$content = isset($metasData[$key]) ? $metasData[$key]->getContent() : null;
$fieldType = isset($metasData[$key]) && $metasData[$key]->getFieldType() != '' ? $metasData[$key]->getFieldType() : $meta['type'];
$data->value->metas[$key] = new Meta($key, $content, $fieldType);
}

$fieldForm
Expand All @@ -101,6 +101,7 @@ public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data)
[
'required' => $fieldDefinition->isRequired,
'label' => $fieldDefinition->getName($formConfig->getOption('languageCode')),
'metaConfig' => $metasConfig
]
)
->setAutoInitialize(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field)
)->set(
$connection->quoteColumn('meta_content'),
$insertQuery->bindValue($meta['meta_content'], null, PDO::PARAM_STR)
)->set(
$connection->quoteColumn('meta_fieldtype'),
$insertQuery->bindValue($meta['meta_fieldtype'], null, PDO::PARAM_STR)
)->set(
$connection->quoteColumn('objectattribute_id'),
$insertQuery->bindValue($field->id, null, PDO::PARAM_INT)
Expand Down
5 changes: 4 additions & 1 deletion bundle/Core/FieldType/Metas/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public function fromHash($hash)
}
$meta = new Meta();
$meta->setName($hashItem['meta_name']);
$meta->setContent($hashItem['meta_content']);
$meta->setFieldType(isset($hashItem['meta_fieldtype']) ? $hashItem['meta_fieldtype'] : '');
$content = isset($hashItem['meta_fieldtype']) && $hashItem['meta_fieldtype'] == "boolean" ? ($hashItem['meta_content'] == "1" ? true : false) : $hashItem['meta_content'];
$meta->setContent($content);
Comment thread
mbouchaala marked this conversation as resolved.
Outdated
$metas[] = $meta;
}

Expand All @@ -208,6 +210,7 @@ public function toHash(SPIValue $value)
$hash[$meta->getName()] = [
'meta_name' => $meta->getName(),
'meta_content' => $meta->getContent(),
'meta_fieldtype' => $meta->getFieldType(),
];
}

Expand Down
41 changes: 33 additions & 8 deletions bundle/Core/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,25 @@ class Meta
*/
protected $content;

/**
* Meta fieldType.
*
* @var string
*/
protected $fieldType;

/**
* Constructor.
*
* @param string $name
* @param string $content
* @param mixed $content
* @param string $fieldType
*/
public function __construct(?string $name = null, ?string $content = null)
public function __construct(?string $name = null, $content = null, ?string $fieldType = null)
{
$this->name = $name;
$this->content = $content;
$this->name = $name;
$this->content = $content;
$this->fieldType = $fieldType;
}

public function getName(): string
Expand All @@ -53,14 +62,26 @@ public function setName(?string $name): self
return $this;
}

public function getContent(): string
public function getFieldType(): string
{
return $this->fieldType ?? '';
}

public function setFieldType(?string $fieldType): self
{
$this->fieldType = $fieldType ?? '';

return $this;
}

public function getContent()
{
return $this->content ?? '';
return $this->content ?? null;
Comment thread
mbouchaala marked this conversation as resolved.
Outdated
}

public function setContent(?string $content): self
public function setContent($content): self
{
$this->content = $content ?? '';
$this->content = $content ?? null;
Comment thread
mbouchaala marked this conversation as resolved.
Outdated

return $this;
}
Expand All @@ -81,6 +102,7 @@ public function attributes(): array
return [
'name',
'content',
'fieldType'
];
}

Expand All @@ -96,6 +118,9 @@ public function attribute(string $name): ?string
case 'content':
return $this->getContent();
break;
case 'fieldType':
return $this->getFieldType();
break;
default:
throw new PropertyNotFoundException($name, \get_class($this));
break;
Expand Down
6 changes: 6 additions & 0 deletions bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public function getConfigTreeBuilder(): TreeBuilder
->prototype('array')
->children()
->scalarNode('label')->isRequired()->end()
->enumNode( 'type' )->values(['boolean', 'text'])->defaultValue( 'text' )->end()
->arrayNode( 'params' )
->children()
->scalarNode( 'label' )->end()
->end()
->end()
Comment thread
mbouchaala marked this conversation as resolved.
Outdated
->scalarNode('default_pattern')->end()
->scalarNode('icon')->end()
->end()
Expand Down
30 changes: 22 additions & 8 deletions bundle/Form/Type/MetaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Novactive\Bundle\eZSEOBundle\Core\Meta;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
Expand All @@ -35,20 +36,33 @@ public function getBlockPrefix(): string

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$label = false;
$type = '';
if (isset($options['metaConfig'][$builder->getName()])) {
$meta = $options['metaConfig'][$builder->getName()];
$type = $meta['type'];
$label = isset($meta['params']) ? $meta['params']['label'] : $label;
}
$builder
->add('name', HiddenType::class)
->add(
'content',
TextType::class,
[
->add('name', HiddenType::class);
if ($type == 'boolean') {
$builder->add('content', CheckboxType::class, [
'label' => $label,
'attr' => [
'class' => 'form-control',
'false_values' => '0'
]
]);
} else {
$builder->add('content', TextType::class, [
'label' => false,
'empty_data' => '',
]
);
]);
}
Comment thread
mbouchaala marked this conversation as resolved.
Outdated
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefault('data_class', Meta::class);
$resolver->setDefaults(['data_class' => Meta::class, 'metaConfig' => null]);
Comment thread
mbouchaala marked this conversation as resolved.
Outdated
}
}
2 changes: 1 addition & 1 deletion bundle/Form/Type/MetasCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function configureOptions(OptionsResolver $resolver): void
'allow_add' => false,
'allow_delete' => false,
'entry_type' => MetaType::class,
'entry_options' => ['required' => false],
'entry_options' => ['required' => false, 'metaConfig' => null],
'required' => false,
'label' => 'field_definition',
'translation_domain' => 'fieldtypes',
Expand Down
8 changes: 6 additions & 2 deletions bundle/Form/Type/MetasFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ public function getBlockPrefix(): string
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('metas', MetasCollectionType::class);
->add('metas', MetasCollectionType::class,
[
'entry_options' => ['required' => false, 'metaConfig' => $options['metaConfig']]
])
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefault('data_class', Value::class);
$resolver->setDefaults([ 'metaConfig' => null, 'data_class' => Value::class]);
}
}
7 changes: 7 additions & 0 deletions bundle/Resources/config/default_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ parameters:
label: 'Twitter - Image'
default_pattern: "<image|picture>"
icon: 'twitter-square'
'robots':
label: 'Robots'
type: 'boolean'
params:
label: 'NOINDEX'
Comment thread
mbouchaala marked this conversation as resolved.
Outdated
default_pattern: 'all'
icon: 'book'
14 changes: 14 additions & 0 deletions bundle/Resources/public/css/views/fields/edit/novaseometas.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,17 @@
float: left;
clear: right;
}

.ez-field-edit--novaseometas .ez-data-source__input-wrapper .ez-data-source__input-wrapper .form-check .form-check-label {
display: none;
}

.ez-field-edit--novaseometas .ez-data-source__input-wrapper .ez-data-source__input-wrapper .form-check .form-check-input {
margin-top: 0;
position: relative;
height: 30px;
}

.ez-field-edit--novaseometas .ez-data-source__input-wrapper .ez-data-source__input-wrapper .form-check .form-check-input:focus {
box-shadow: none;
}
2 changes: 2 additions & 0 deletions bundle/Resources/sql/update-shema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `novaseo_meta`
ADD `meta_fieldtype` varchar(255) COLLATE 'utf8_general_ci' NOT NULL AFTER `meta_content`;
2 changes: 2 additions & 0 deletions bundle/Resources/views/fields/novaseometas.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<meta property="{{ meta.name }}" content="{{ meta.content | replace({' ': '%20'}) }}"/>
{% elseif meta.name|trim starts with "og" %}
<meta property="{{ meta.name }}" content="{{ meta.content }}"/>
{% elseif meta.name == "robots" and meta.content %}
<meta name="{{ meta.name }}" content="noindex"/>
{% else %}
<meta name="{{ meta.name }}" content="{{ meta.content }}"/>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion bundle/Resources/views/fields/novaseometas_admin.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<li class="ez-field meta-value">
{% set default_value = nova_ezseo.fieldtype_metas[meta.name] %}
<b>{{ default_value.label }}:</b>
{{ meta.isEmpty() ? default_value.default_pattern|raw|escape : meta.content }}
{{ meta.isEmpty() ? default_value.default_pattern|raw|escape : (meta.name == 'robots' ? (meta.content ? 'noindex' : default_value.default_pattern|raw|escape) : meta.content) }}
</li>
{% endif %}
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion documentation/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ _novaezseo_routes:

### Create the table

See the file `bundle/Resources/sql/shema.sql`
See the folder `bundle/Resources/sql`


### Remove the Robots.txt (native RewriteRules )
Expand Down