Creates a default block.

@param string          $type
@param array           $data
@param EM\RowInterface $row

@return EM\BlockInterface
327716
public function createDefaultBlock($type = null, array $data = [], EM\RowInterface $row = null)
    {
        return $this->getBlockManager()->create($row, $type, $data);
    }
1014156
public static function getAndAssertActiveBlock($type)
    {
        $active_block = static::getActive();
        $current = get_class($active_block->activeBlock());
        if ( !is_a($active_block->activeBlock(), $type)) {
            throw new Exception("Improperly nested block. Expected a $type, got a $current");
        }
        return $active_block;
    }
79632
public function createNamed($type, array $options = [])
    {
        if ($type instanceof BlockInterface) {
            return $type;
        }

        $name = $this->getBlockName($options);

        return $this->factory->createNamed($name, $type, null, $options);
    }
936824
public function createBlock($ownerId, $type, $parentId, $placeholder, $sort, $data = null)
    {
        $owner = $this->find($ownerId);
        $version = $this->getNewVersion($owner);
        $className = $this->em->getClassMetadata($type)->getName();
        $block = new $className();
        $parent = $this->find($parentId ?: $ownerId);

        $block->setRootVersion($version);
        $block->setPosition($placeholder);
        $block->setSort(0); // < default, gets recalculated later for entire level
        $block->setLevel(0); // < need to be calculated when putting in the tree

        // Set owner
        $block->setOwner($owner);
        $owner->addOwning($block);
        $owner->setRootVersion($version);

        // This should replaced with a more hardened function
        if ($data) {
            foreach ($data as $attribute => $value) {
                $method = "set$attribute";
                $block->$method($value);
            }
        }

        $block->setParent($parent);
        $parent->setRootVersion($version);

        // Save now, rest will be in changeset. All we do is a create a stub entry anyway.
        $this->save($block);

        if (count($sort) > 1) {
            // Replace the zero value in the posted sort array
            // with the newly created id to perform sorting
            $id = $block->getId();
            $sort = array_map(
                function ($v) use ($id) {
                    return $v == "" || $v == "0" ? $id : $v;
                },
                $sort
            );

            $siblings = $this->getSiblings($block, $version);
            $siblings[] = $block;
            if ($siblings) {
                $siblings = $this->sortBlocksByDirective($siblings, $sort);

                foreach ($siblings as $sibling) {
                    $this->save($sibling);
                }
            }
        } else {
        }

        return $block;
    }
609961
public function newBlockAction($page_id, $type)
    {
        $em = $this->getDoctrine()->getManager();
        $page = $em->getRepository('AmulenPageBundle:Page')->find($page_id);

        $entity = new Block();
        $entity->setType($type);
        $entity->setPage($page);
        $form = $this->createBlockCreateForm($entity);

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
1084577
public function buildFluentData(string $type, $row, Fluent $control): FieldContract
    {
        // set the name of the control
        $name = $control->get('name');
        $value = $this->resolveFieldValue($name, $row, $control);

        $data = new Field([
            'method' => '',
            'type' => '',
            'options' => [],
            'checked' => false,
            'attributes' => [],
            'name' => $name,
            'value' => $value,
        ]);

        return $this->resolveFieldType($type, $data);
    }
270666
public function buildFieldByType($type, $row, Fluent $control)
    {


        $attributes = (array) $control->attributes;

        $html              = $this->html;
        $templates         = $this->templates;
        $data              = $this->buildFluentData($type, $row, $control);
        $method            = $data->get('method');
        $data->options($this->getOptionList($row, $control));
        $data->checked($control->get('checked'));
        $data->optionsData = $control->get('optionsData') ?: [];

        $data->attributes($html->decorate($attributes, Arr::get($templates, $method)));
        if ($type === 'dropzone') {
            $data->label = $control->get('label');
        }
        return $data;
    }
710384
public function addType($name, $type, $data = null, $options = array())
    {
        $this->types[$name] = $type;
        $this->data[$name] = $data;
        $this->options[$name] = $options;

        return $this;
    }
713637
public function custom(Column\Custom $column, array $row)
    {
        $html = call_user_func($column->getCustom(), $row);
        return $this->post($html, $column, $row);
    }
637738
private function createBottomHeadingRow(array $rows)
    {
        $elements = array();

        if ($this->options[self::GRID_PARAM_BATCH] === true) {
            $elements[] = $this->createColumn(null, null);
        }

        foreach ($rows as $row) {
            // Ignore if configuration for current column isn't provided
            if (!$this->hasColumnConfiguration($row[self::GRID_PARAM_COLUMN])) {
                continue;
            }

            // Find out whether a column needs to have a filter
            $filter = $this->findOptionByColumn($row[self::GRID_PARAM_COLUMN], self::GRID_PARAM_FILTER);

            // Use provided name if available, otherwise name it as a column
            $inputName = isset($row[self::GRID_PARAM_NAME]) ? $row[self::GRID_PARAM_NAME] : $row[self::GRID_PARAM_COLUMN];

            // Full-qualified input name
            $name = $this->createInputName(self::GRID_PARAM_FILTER, $inputName);

            if ($filter) {
                // If filter is array, then assume its for select
                $selected = $this->filter->get($inputName);

                if (is_array($filter)) {
                    $filter = array_replace(array('' => ''), $filter);
                    $elements[] = $this->createInput('createHeader', $row[self::GRID_PARAM_COLUMN], $name, $selected, $filter);
                    // If explicit boolean filter provided
                } else if ($filter === 'boolean') {
                    $options = array(
                        '0' => 'No',
                        '1' => 'Yes'
                    );

                    // Translate boolean values on demand
                    if ($this->hasTranslator()) {
                        $options = $this->translator->translateArray($options);
                    }

                    $filter = array_replace(array('' => ''), $options);
                    $elements[] = $this->createInput('createHeader', $row[self::GRID_PARAM_COLUMN], $name, $selected, $filter);
                    
                } else {
                    $elements[] = $this->createInput('createHeader', $row[self::GRID_PARAM_COLUMN], $name, $selected);
                }

            } else {
                $elements[] = $this->createColumn(null, '');
            }
        }

        if ($this->hasActions()) {
            $elements[] = $this->createTextHeader('');
        }

        return $this->createTableRow($elements);
    }
1374147
public function renderBlock($block, $type = null, array $data = [])
    {
        if (is_string($block)) {
            if (null === $element = $this->editor->getRepository()->findBlockByName($block)) {
                $this->persist($element = $this->editor->getBlockManager()->create($block, $type, $data));
            }
            $block = $element;
        }

        if ($block instanceof EM\BlockInterface) {
            $this->tagManager->addTags($block->getEntityTag());

            $block = $this->editor->getViewBuilder()->buildBlock($block);
        }

        if (!$block instanceof View\BlockView) {
            throw new Exception\InvalidArgumentException(
                'Expected string or instance of ' .
                EM\BlockInterface::class . ' or ' .
                View\BlockView::class
            );
        }

        return $this->getTemplate()->renderBlock('cms_block', [
            'block' => $block,
        ]);
    }
224886
protected function createForm($type, $data = null, array $options = array())
    {
        return $this->factory->create($type, $data, $options);
    }
1228226
public function updateNodeSet(RowInterface $row, $propertyData)
    {
        $node = $row->getNode($propertyData['selector']);
        $value = $propertyData['value'];

        if ($value instanceof FunctionOperand) {
            $value = $propertyData['value'];
            $value = $value->execute($this->functionMapSet, $row);
        }

        $node->setProperty($propertyData['name'], $value);
    }
834415
public function build( $data = null, $type = null ) {

		if ( ! empty( $data ) ) {
			$this->set_data( $data );
		}

		if ( ! empty( $type ) && in_array( $type, $this->types, true ) ) {
			$this->type = $type;
		}

		if ( method_exists( $this, "build_{$this->type}" ) ) {
			call_user_func( array( $this, 'build_' . $this->type ) );
		}

		return $this->data;
	}
1354629
public function createDefaultContainer($type = null, array $data = [], EM\ContentInterface $content = null)
    {
        return $this->getContainerManager()->create($content, $type, $data);
    }
929331
public function createRow(array $data = array(), $defaultSource = null)
    {
        $cols     = $this->_getCols();
        $defaults = array_combine($cols, array_fill(0, count($cols), null));

        // nothing provided at call-time, take the class value
        if ($defaultSource == null) {
            $defaultSource = $this->_defaultSource;
        }

        if (!in_array($defaultSource, array(self::DEFAULT_CLASS, self::DEFAULT_DB, self::DEFAULT_NONE))) {
            $defaultSource = self::DEFAULT_NONE;
        }

        if ($defaultSource == self::DEFAULT_DB) {
            foreach ($this->_metadata as $metadataName => $metadata) {
                if (($metadata['DEFAULT'] != null) &&
                    ($metadata['NULLABLE'] !== true || ($metadata['NULLABLE'] === true && isset($this->_defaultValues[$metadataName]) && $this->_defaultValues[$metadataName] === true)) &&
                    (!(isset($this->_defaultValues[$metadataName]) && $this->_defaultValues[$metadataName] === false))) {
                    $defaults[$metadataName] = $metadata['DEFAULT'];
                }
            }
        } elseif ($defaultSource == self::DEFAULT_CLASS && $this->_defaultValues) {
            foreach ($this->_defaultValues as $defaultName => $defaultValue) {
                if (array_key_exists($defaultName, $defaults)) {
                    $defaults[$defaultName] = $defaultValue;
                }
            }
        }

        $config = array(
            'table'    => $this,
            'data'     => $defaults,
            'readOnly' => false,
            'stored'   => false
        );

        $rowClass = $this->getRowClass();
        if (!class_exists($rowClass)) {
            // require_once 'Zend/Loader.php';
            Zend_Loader::loadClass($rowClass);
        }
        $row = new $rowClass($config);
        $row->setFromArray($data);
        return $row;
    }
329766
protected function makeOutputBlock($type, $selectors = null)
    {
        $b = new stdclass();
        $b->lines = array();
        $b->children = array();
        $b->selectors = $selectors;
        $b->type = $type;
        $b->parent = $this->scope;

        return $b;
    }