public function newElementForm()
    {
        $parsedBody = $this->request->getParsedBody();

        $form['block_key'] = $parsedBody['blockKey'];
        $form['definition'] = $parsedBody['elementType'];
        $form['element_sort'] = 1;

        // Only include element type options if the string is not empty
        if (!empty($parsedBody['elementTypeOptions'])) {
            $form['elementTypeOptions'] = explode(',', $parsedBody['elementTypeOptions']);
        }

        $template = '{% import "@admin/editElementMacro.html" as form %}';
        $template .= ' {{ form.elementForm(element, element.block_key, element.elementTypeOptions) }}';
        $elementFormHtml = $this->container->view->fetchFromString($template, ['element' => $form]);

        // Set the response type
        $r = $this->response->withHeader('Content-Type', 'application/json');

        return $r->write(json_encode(["html" => $elementFormHtml]));
    }
public function newElementForm()
    {
        $parsedBody = $this->request->getParsedBody();

        $form['block_key'] = $parsedBody['blockKey'];
        $form['definition'] = $parsedBody['elementType'];
        $form['element_sort'] = 1;

        // Only include element type options if the string is not empty
        if (!empty($parsedBody['elementTypeOptions'])) {
            $form['elementTypeOptions'] = explode(',', $parsedBody['elementTypeOptions']);
        }

        $template = '{% import "@admin/editElementMacro.html" as form %}';
        $template .= ' {{ form.elementForm(element, element.block_key, element.elementTypeOptions) }}';
        $elementFormHtml = $this->container->view->fetchFromString($template, ['element' => $form]);

        // Set the response type
        $r = $this->response->withHeader('Content-Type', 'application/json');

        return $r->write(json_encode(["html" => $elementFormHtml]));
    }
public function newElementForm ( ) { $ parsedBody = $ this -> request -> getParsedBody ( ) ; $ form [ 'block_key' ] = $ parsedBody [ 'blockKey' ] ; $ form [ 'definition' ] = $ parsedBody [ 'elementType' ] ; $ form [ 'element_sort' ] = 1 ; // Only include element type options if the string is not empty if ( ! empty ( $ parsedBody [ 'elementTypeOptions' ] ) ) { $ form [ 'elementTypeOptions' ] = explode ( ',' , $ parsedBody [ 'elementTypeOptions' ] ) ; } $ template = '{% import "@admin/editElementMacro.html" as form %}' ; $ template .= ' {{ form.elementForm(element, element.block_key, element.elementTypeOptions) }}' ; $ elementFormHtml = $ this -> container -> view -> fetchFromString ( $ template , [ 'element' => $ form ] ) ; // Set the response type $ r = $ this -> response -> withHeader ( 'Content-Type' , 'application/json' ) ; return $ r -> write ( json_encode ( [ "html" => $ elementFormHtml ] ) ) ; }
New Element Form

Renders new element form with initial values, and returns via Ajax to browser.
At a minimum, the element form is expecting these values:
- blockKey
- elementTypeDefault
- elementSort
- elementTypeOptions | optional, comma separated list of approved element types
New Element Form