<?php
namespace Products\NotificationsBundle\Form\Forms\Messages;
use App\Entity\System\School;
use Cms\CoreBundle\Form\Type\DateTimeType;
use Cms\FrontendBundle\Service\ResolverManager;
use Products\NotificationsBundle\Entity\Notifications\Message;
use Products\NotificationsBundle\Form\Type\BannerChoiceType;
use Products\NotificationsBundle\Form\Type\FancyEntityType;
use Products\NotificationsBundle\Form\Type\MessageChoiceType;
use Products\NotificationsBundle\Form\Type\SteppedDateTimeType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
/**
* Class MessageChannelsForm
* @package Products\NotificationsBundle\Form\Forms\Messages
*/
class MessageChannelsForm extends AbstractType
{
/**
* @var ResolverManager
*/
protected ResolverManager $rm;
/**
* @param ResolverManager $rm
*/
public function __construct(ResolverManager $rm)
{
$this->rm = $rm;
}
/**
* {@inheritDoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options): void
{
$view->children['action']->setRendered();
}
/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
/** @var Message $message */
$message = $builder->getData();
$builder
->add('scheduled', ChoiceType::class, [
'label' => false,
'expanded' => true,
'choices' => [
'Send Now' => false,
'Schedule for Later' => true,
],
'data' => false,
'mapped' => false,
'required' => true,
])
->add('scheduledAt', DateTimeType::class, [
'widget' => 'single_text',
'mapped' => false,
'required' => false,
'show_timezone' => false,
])
->add('branding', FancyEntityType::class, [
'required' => false,
'placeholder' => "Select branding",
'empty_data' => null,
'label_tooltip' => true,
'class' => School::class,
'choice_label' => 'name',
'choices' => array_values(array_filter($this->rm->getSchoolResolver()->resolveSchoolsByLists($message->getListsAsArray()))) ?: [$this->rm->getSchoolResolver()->resolveDistrictByTenant($message)],
])
->add('action', HiddenType::class, [
'mapped' => false,
'required' => false,
])
->add('channels', ChannelsType::class, [
'required' => false,
])
// WEBSITE CHANNEL
->add('websiteEndDateTime', SteppedDateTimeType::class, [
'label_tooltip' => 'Select the date and time your website alert should expire from the website.',
])
->add('websiteLevel', MessageChoiceType::class, [
'label_tooltip' => "Select the priority of your website alert. <a target='blank' href='https://help.schoolnow.com/kb/how-do-i-add-an-emergency-alert'>Learn more</a>",
])
->add('websiteBehavior', BannerChoiceType::class, [
'label_tooltip' => "Selecting banner with popup will require the user to dismiss the alert. <a target='blank' href='https://help.schoolnow.com/kb/how-do-i-add-an-emergency-alert'>Learn more</a>",
])
// FACEBOOK CHANNEL
->add('facebookNote', TextType::class, [
'required' => false,
'label_tooltip' => true,
])
// TWITTER CHANNEL
->add('twitterNote', TextType::class, [
'required' => false,
'label_tooltip' => true,
])
->add('translations', MessageTranslationsForm::class, [
'label_tooltip' => true,
'data' => $builder->getData(),
'mapped' => false,
])
;
}
}