src/Entity/Pages/NewsPage.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Pages;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Kunstmaan\ArticleBundle\Entity\AbstractArticlePage;
  8. use Kunstmaan\NodeSearchBundle\Helper\SearchTypeInterface;
  9. use Kunstmaan\PagePartBundle\Helper\HasPageTemplateInterface;
  10. use Kunstmaan\NodeBundle\Entity\HideSidebarInNodeEditInterface;
  11. use Kunstmaan\MediaBundle\Entity\Media;
  12. use App\Form\Pages\NewsPageAdminType;
  13. use Symfony\Component\Form\AbstractType;
  14. use App\Entity\NewsTag;
  15. use App\Repository\NewsPageRepository;
  16. #[ORM\Entity(repositoryClass:NewsPageRepository::class)]
  17. #[ORM\Table(name'app_news_pages')]
  18. #[ORM\HasLifecycleCallbacks]
  19. class NewsPage extends AbstractArticlePage implements HasPageTemplateInterfaceSearchTypeInterfaceHideSidebarInNodeEditInterface
  20. {
  21.    /**
  22.      * @var ArrayCollection
  23.      *
  24.      */
  25.     
  26.     #[ORM\ManyToMany(targetEntityNewsTag::class,cascade:["persist"])]
  27.           #[ORM\JoinTable(name'app_news_tag_page_tags')]
  28.           #[ORM\JoinColumn(name'news_page_id'referencedColumnName'id')]
  29.           #[ORM\InverseJoinColumn(name'news_tag_id'referencedColumnName'id')]
  30.           protected $tags;
  31.     
  32.     #[ORM\Column(name'image_alt_text'type:"text"nullable:true)]
  33.           protected string $imageAltText;
  34.      
  35.     #[ORM\ManyToOne(targetEntityMedia::class)]
  36.           #[ORM\JoinColumn(name'image_id'referencedColumnName'id')]
  37.           protected $image;
  38.     
  39.     public function __construct()
  40.     {
  41.         $this->tags = new ArrayCollection();
  42.     }
  43.         /**
  44.      * @param App\Entity\NewsTag $tag
  45.      * @return $this
  46.      */
  47.     public function setTags($tag)
  48.     {
  49.         $this->tags $tag;
  50.         return $this;
  51.     }
  52.     /**
  53.      * @return ArrayCollection
  54.      */
  55.     public function getTags()
  56.     {
  57.         return $this->tags;
  58.     }
  59.     public function addTag(NewsTag $tag)
  60.     {
  61.         $this->tags[] = $tag;
  62.         return $this;
  63.     }
  64.     public function removeTag(NewsTag $tag)
  65.     {
  66.         $this->tags->removeElement($tag);
  67.     }
  68.     /**
  69.      * Returns the default backend form type for this page
  70.      *
  71.      * @return string
  72.      */
  73.     public function getDefaultAdminType()
  74.     {
  75.         return NewsPageAdminType::class;
  76.     }
  77.     /**
  78.      * {@inheritdoc}
  79.      */
  80.     public function getSearchType()
  81.     {
  82.         return 'News';
  83.     }
  84.     /**
  85.      * @return array
  86.      */
  87.     public function getPagePartAdminConfigurations()
  88.     {
  89.         return array('newsmain');
  90.     }
  91.     /**
  92.      * {@inheritdoc}
  93.      */
  94.     public function getPageTemplates()
  95.     {
  96.         return array('newspage');
  97.     }
  98.     public function getDefaultView()
  99.     {
  100.         return 'Pages/NewsPage/view.html.twig';
  101.     }
  102.     /**
  103.      * Before persisting this entity, check the date.
  104.      * When no date is present, fill in current date and time.
  105.      *
  106.      * @ORM\PrePersist
  107.      */
  108.      #[ORM\PrePersist]
  109.     public function _prePersist()
  110.     {
  111.         // Set date to now when none is set
  112.         if ($this->date == null) {
  113.             $this->setDate(new \DateTime());
  114.         }
  115.     }
  116.     /**
  117.      * Set imageAltText
  118.      *
  119.      * @param string $imageAltText
  120.      *
  121.      * @return NewsPage
  122.      */
  123.     public function setImageAltText($imageAltText)
  124.     {
  125.         $this->imageAltText $imageAltText;
  126.         return $this;
  127.     }
  128.     /**
  129.      * Get imageAltText
  130.      *
  131.      * @return string
  132.      */
  133.     public function getImageAltText()
  134.     {
  135.         return $this->imageAltText;
  136.     }
  137.     /**
  138.      * Set image
  139.      *
  140.      * @param \Kunstmaan\MediaBundle\Entity\Media $image
  141.      *
  142.      * @return NewsPage
  143.      */
  144.     public function setImage(\Kunstmaan\MediaBundle\Entity\Media $image null)
  145.     {
  146.         $this->image $image;
  147.         return $this;
  148.     }
  149.     /**
  150.      * Get image
  151.      *
  152.      * @return \Kunstmaan\MediaBundle\Entity\Media
  153.      */
  154.     public function getImage()
  155.     {
  156.         return $this->image;
  157.     }
  158. }