-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ibexa4 : Add meta checkbox field type for rendering meta robots (#110)
* * ibexa4 : Add meta checkbox field type for rendering meta robots --------- Co-authored-by: Florian ALEXANDRE <f.alexandre@novactive.com>
- Loading branch information
1 parent
7c04882
commit 4b8bf86
Showing
17 changed files
with
334 additions
and
65 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
bundle/Core/FieldType/MetaFieldConverter/SeoMetadataBooleanFieldType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* NovaeZSEOBundle SeoMetadataBooleanFieldType. | ||
* | ||
* @package Novactive\Bundle\eZSEOBundle | ||
* | ||
* @author Novactive <novaseobundle@novactive.com> | ||
* @copyright 2021 Novactive | ||
* @license https://github.com/Novactive/NovaeZSEOBundle/blob/master/LICENSE MIT Licence | ||
*/ | ||
|
||
namespace Novactive\Bundle\eZSEOBundle\Core\FieldType\MetaFieldConverter; | ||
|
||
use Novactive\Bundle\eZSEOBundle\Core\Meta; | ||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class SeoMetadataBooleanFieldType extends SeoMetadataDefaultFieldType | ||
{ | ||
public const IDENTIFIER = 'boolean'; | ||
|
||
public function fromHash($hash): Meta | ||
{ | ||
$meta = parent::fromHash($hash); | ||
$content = '1' == $hash['meta_content'] ? true : false; | ||
$meta->setContent($content); | ||
|
||
return $meta; | ||
} | ||
|
||
public function mapForm(FormBuilderInterface &$builder, array $params) | ||
{ | ||
$option = [ | ||
'class' => 'form-control', | ||
'false_values' => '0', | ||
]; | ||
$builder->add( | ||
'content', | ||
CheckboxType::class, | ||
array_merge($params, $option) | ||
); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
bundle/Core/FieldType/MetaFieldConverter/SeoMetadataChoiceFieldType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* NovaeZSEOBundle SeoMetadataChoiceFieldType. | ||
* | ||
* @package Novactive\Bundle\eZSEOBundle | ||
* | ||
* @author Novactive <novaseobundle@novactive.com> | ||
* @copyright 2021 Novactive | ||
* @license https://github.com/Novactive/NovaeZSEOBundle/blob/master/LICENSE MIT Licence | ||
*/ | ||
|
||
namespace Novactive\Bundle\eZSEOBundle\Core\FieldType\MetaFieldConverter; | ||
|
||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class SeoMetadataChoiceFieldType extends SeoMetadataDefaultFieldType | ||
{ | ||
public const IDENTIFIER = 'select'; | ||
|
||
public function mapForm(FormBuilderInterface &$builder, array $params) | ||
{ | ||
$builder->add( | ||
'content', | ||
ChoiceType::class, | ||
$params | ||
); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
bundle/Core/FieldType/MetaFieldConverter/SeoMetadataDefaultFieldType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* NovaeZSEOBundle SeoMetadataDefaultFieldType. | ||
* | ||
* @package Novactive\Bundle\eZSEOBundle | ||
* | ||
* @author Novactive <novaseobundle@novactive.com> | ||
* @copyright 2021 Novactive | ||
* @license https://github.com/Novactive/NovaeZSEOBundle/blob/master/LICENSE MIT Licence | ||
*/ | ||
|
||
namespace Novactive\Bundle\eZSEOBundle\Core\FieldType\MetaFieldConverter; | ||
|
||
use Novactive\Bundle\eZSEOBundle\Core\Meta; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class SeoMetadataDefaultFieldType implements SeoMetadataFieldTypeInterface | ||
{ | ||
public const IDENTIFIER = 'text'; | ||
|
||
public function support(string $fieldType): bool | ||
{ | ||
return static::IDENTIFIER === $fieldType; | ||
} | ||
|
||
public function fromHash($hash): Meta | ||
{ | ||
$meta = new Meta(); | ||
$meta->setName($hash['meta_name']); | ||
$meta->setFieldType(self::IDENTIFIER); | ||
$content = $hash['meta_content']; | ||
$meta->setContent($content); | ||
|
||
return $meta; | ||
} | ||
|
||
public function mapForm(FormBuilderInterface &$builder, array $params) | ||
{ | ||
$params['empty_data'] = ''; | ||
$builder->add( | ||
'content', | ||
TextType::class, | ||
$params | ||
); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
bundle/Core/FieldType/MetaFieldConverter/SeoMetadataFieldTypeInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* NovaeZSEOBundle SeoMetadataFieldTypeInterface. | ||
* | ||
* @package Novactive\Bundle\eZSEOBundle | ||
* | ||
* @author Novactive <novaseobundle@novactive.com> | ||
* @copyright 2021 Novactive | ||
* @license https://github.com/Novactive/NovaeZSEOBundle/blob/master/LICENSE MIT Licence | ||
*/ | ||
|
||
namespace Novactive\Bundle\eZSEOBundle\Core\FieldType\MetaFieldConverter; | ||
|
||
use Novactive\Bundle\eZSEOBundle\Core\Meta; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
interface SeoMetadataFieldTypeInterface | ||
{ | ||
/** | ||
* @param $hash | ||
*/ | ||
public function fromHash($hash): Meta; | ||
|
||
public function support(string $fieldType): bool; | ||
|
||
public function mapForm(FormBuilderInterface &$builder, array $params); | ||
} |
82 changes: 82 additions & 0 deletions
82
bundle/Core/FieldType/MetaFieldConverter/SeoMetadataFieldTypeRegistry.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/** | ||
* NovaeZSEOBundle SeoMetadataFieldTypeRegistry. | ||
* | ||
* @package Novactive\Bundle\eZSEOBundle | ||
* | ||
* @author Novactive <novaseobundle@novactive.com> | ||
* @copyright 2021 Novactive | ||
* @license https://github.com/Novactive/NovaeZSEOBundle/blob/master/LICENSE MIT Licence | ||
*/ | ||
|
||
namespace Novactive\Bundle\eZSEOBundle\Core\FieldType\MetaFieldConverter; | ||
|
||
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class SeoMetadataFieldTypeRegistry | ||
{ | ||
/** @var SeoMetadataFieldTypeInterface[] */ | ||
protected $metaFieldTypes; | ||
|
||
/** @var ConfigResolverInterface */ | ||
protected $configResolver; | ||
|
||
/** | ||
* SeoMetadataFieldTypeRegistry constructor. | ||
* | ||
* @param SeoMetadataFieldTypeInterface[] $metaFieldTypes | ||
*/ | ||
public function __construct(iterable $metaFieldTypes) | ||
{ | ||
foreach ($metaFieldTypes as $metaFieldType) { | ||
$this->addMetaFieldType($metaFieldType); | ||
} | ||
} | ||
|
||
/** | ||
* @required | ||
*/ | ||
public function setConfigResolver(ConfigResolverInterface $configResolver): void | ||
{ | ||
$this->configResolver = $configResolver; | ||
} | ||
|
||
public function addMetaFieldType(SeoMetadataFieldTypeInterface $metaFieldType): void | ||
{ | ||
$this->metaFieldTypes[] = $metaFieldType; | ||
} | ||
|
||
public function fromHash($hash): array | ||
{ | ||
$metasConfig = $this->configResolver->getParameter('fieldtype_metas', 'nova_ezseo'); | ||
|
||
$metas = []; | ||
foreach ($hash as $hashItem) { | ||
if (!is_array($hashItem)) { | ||
continue; | ||
} | ||
$fieldConfig = $metasConfig[$hashItem['meta_name']] ?? null; | ||
$fieldType = $fieldConfig['type'] ?? SeoMetadataDefaultFieldType::IDENTIFIER; | ||
foreach ($this->metaFieldTypes as $metaFieldType) { | ||
if (!$metaFieldType->support($fieldType)) { | ||
continue; | ||
} | ||
$metas[] = $metaFieldType->fromHash($hashItem); | ||
} | ||
} | ||
|
||
return $metas; | ||
} | ||
|
||
public function mapForm(FormBuilderInterface &$builder, array $params, string $fieldType) | ||
{ | ||
foreach ($this->metaFieldTypes as $metaFieldType) { | ||
if (!$metaFieldType->support($fieldType)) { | ||
continue; | ||
} | ||
$metaFieldType->mapForm($builder, $params); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.