addElement('text', 'title', ['label' => 'Title', 'required' => true]); $this->addElement('textarea', 'introduction', ['label' => 'Introduction']); $this->addElement( 'text', 'youtubeUrl', [ 'label' => 'Video', 'maxlength' => 255, 'filters' => [ 'StringTrim', ['Callback', ['callback' => [$this, 'youTubeCodeToUrl']]] ], 'validators' => ['Url', 'YoutubeUrl'], 'description' => 'YouTube Video Url (e.g.: https://www.youtube.com/watch?v=abcdefghigk)' . ' or code (e.g.: abcdefghigk)', ] ); $this->addElement('htmlEditor', 'content', ['label' => 'Content', 'hasMsWordNote' => true]); $this->addQuestions(); $this->addElement( 'checkbox', 'enabled', [ 'label' => 'Show on user end', 'decoration' => 'simple', 'value' => 'y' ] ); return parent::_initElements(); } public function youTubeCodeToUrl($value) { if (preg_match('/^(\w|-){11}$/', $value)) { return 'https://www.youtube.com/watch?v=' . $value; } return $value; } protected function addQuestions() { $name = 'questions'; $options = [ 'name' => $name, 'defaults' => Qs_Array::get($this->_defaults, 'questions', []), 'orientation' => Table::ORIENTATION_VERTICAL, 'itemClass' => QuestionRow::CLASS, 'itemName' => 'Question', 'itemsName' => 'Questions', ]; $this->addSubForm(new Table($options), $name); return $this; } }