Skip to content

Commit

Permalink
Dynamic DiscriminatorMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarek Jakubowski committed Apr 19, 2019
1 parent 43b104a commit f02cefc
Show file tree
Hide file tree
Showing 26 changed files with 279 additions and 55 deletions.
41 changes: 10 additions & 31 deletions src/Entity/Field.php
Expand Up @@ -26,33 +26,9 @@
* })
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string", length=191)
* @ORM\DiscriminatorMap({
* "generic" = "field",
* "block" = "Bolt\Entity\Field\BlockField",
* "checkbox" = "Bolt\Entity\Field\CheckboxField",
* "date" = "Bolt\Entity\Field\DateField",
* "embed" = "Bolt\Entity\Field\EmbedField",
* "file" = "Bolt\Entity\Field\FileField",
* "filelist" = "Bolt\Entity\Field\FilelistField",
* "float" = "Bolt\Entity\Field\FloatField",
* "geolocation" = "Bolt\Entity\Field\GeolocationField",
* "hidden" = "Bolt\Entity\Field\HiddenField",
* "html" = "Bolt\Entity\Field\HtmlField",
* "image" = "Bolt\Entity\Field\ImageField",
* "imagelist" = "Bolt\Entity\Field\ImagelistField",
* "integer" = "Bolt\Entity\Field\IntegerField",
* "markdown" = "Bolt\Entity\Field\MarkdownField",
* "number" = "Bolt\Entity\Field\NumberField",
* "repeater" = "Bolt\Entity\Field\RepeaterField",
* "select" = "Bolt\Entity\Field\SelectField",
* "slug" = "Bolt\Entity\Field\SlugField",
* "templateselect" = "Bolt\Entity\Field\TemplateselectField",
* "text" = "Bolt\Entity\Field\TextField",
* "textarea" = "Bolt\Entity\Field\TextareaField",
* "video" = "Bolt\Entity\Field\VideoField"
* })
* @ORM\DiscriminatorMap({"generic" = "Field"})
*/
class Field implements Translatable
class Field implements Translatable, FieldInterface
{
/**
* @ORM\Id()
Expand Down Expand Up @@ -169,11 +145,6 @@ public function setName(string $name): self
return $this;
}

public function getType(): ?string
{
return $this->getDefinition()->get('type');
}

public function get($key)
{
return isset($this->value[$key]) ? $this->value[$key] : null;
Expand Down Expand Up @@ -282,4 +253,12 @@ public function setParent(?self $parent): self

return $this;
}

/**
* @Groups("get_field")
*/
public static function getType(): string
{
return 'generic';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/BlockField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class BlockField extends Field
class BlockField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'block';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/CheckboxField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class CheckboxField extends Field
class CheckboxField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'checkbox';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/DateField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class DateField extends Field
class DateField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'date';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/EmbedField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class EmbedField extends Field
class EmbedField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'embed';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/FileField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class FileField extends Field
class FileField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'file';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/FilelistField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class FilelistField extends Field
class FilelistField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'filelist';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/FloatField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class FloatField extends Field
class FloatField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'float';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/GeolocationField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class GeolocationField extends Field
class GeolocationField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'geolocation';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/HiddenField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class HiddenField extends Field
class HiddenField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'hidden';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/HtmlField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class HtmlField extends Field implements Excerptable
class HtmlField extends Field implements Excerptable, FieldInterface
{
public static function getType(): string
{
return 'html';
}
}
8 changes: 7 additions & 1 deletion src/Entity/Field/ImageField.php
Expand Up @@ -5,14 +5,20 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;
use League\Glide\Urls\UrlBuilderFactory;

/**
* @ORM\Entity
*/
class ImageField extends Field
class ImageField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'image';
}

public function __toString(): string
{
return $this->getPath();
Expand Down
7 changes: 6 additions & 1 deletion src/Entity/Field/ImagelistField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class ImagelistField extends Field
class ImagelistField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'imagelist';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/IntegerField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class IntegerField extends Field
class IntegerField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'integer';
}
}
8 changes: 7 additions & 1 deletion src/Entity/Field/MarkdownField.php
Expand Up @@ -5,14 +5,20 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Bolt\Utils\Markdown;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class MarkdownField extends Field implements Excerptable
class MarkdownField extends Field implements Excerptable, FieldInterface
{
public static function getType(): string
{
return 'markdown';
}

public function __toString(): string
{
$markdown = new Markdown();
Expand Down
7 changes: 6 additions & 1 deletion src/Entity/Field/NumberField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class NumberField extends Field
class NumberField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'number';
}
}
7 changes: 6 additions & 1 deletion src/Entity/Field/RepeaterField.php
Expand Up @@ -5,11 +5,16 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class RepeaterField extends Field
class RepeaterField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'repeater';
}
}
8 changes: 7 additions & 1 deletion src/Entity/Field/SelectField.php
Expand Up @@ -5,13 +5,19 @@
namespace Bolt\Entity\Field;

use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class SelectField extends Field
class SelectField extends Field implements FieldInterface
{
public static function getType(): string
{
return 'select';
}

public function getValue(): ?array
{
if (empty($this->value)) {
Expand Down

0 comments on commit f02cefc

Please sign in to comment.