/** * Deprecated since 1.1.0 * * @param Neo_BlockModel $block * @return mixed */ public function children(Neo_BlockModel $block) { craft()->deprecator->log('NeoVariable::children()', "<code>craft.neo.children(block)</code> has been deprecated. Use <code>block.children</code> instead."); $owner = $block->getOwner(); $type = $block->getType(); $field = craft()->fields->getFieldById($type->fieldId); $criteria = craft()->elements->getCriteria(Neo_ElementType::NeoBlock); $criteria->ownerId = $owner->id; $criteria->fieldId = $field->id; $criteria->locale = $owner->locale; $criteria->descendantOf = $block; $criteria->descendantDist = 1; return $criteria; }
/** * */ public function actionRenderBlocks() { $this->requireAjaxRequest(); $this->requirePostRequest(); $blocks = craft()->request->getPost('blocks'); $namespace = craft()->request->getPost('namespace'); $locale = craft()->request->getPost('locale'); $renderedBlocks = []; foreach ($blocks as $rawBlock) { $type = craft()->neo->getBlockTypeById($rawBlock['type']); $block = new Neo_BlockModel(); $block->modified = true; $block->typeId = $rawBlock['type']; $block->level = $rawBlock['level']; $block->enabled = isset($rawBlock['enabled']); $block->collapsed = isset($rawBlock['collapsed']); $block->locale = $locale; if (!empty($rawBlock['content'])) { $block->setContentFromPost($rawBlock['content']); } $renderedBlocks[] = ['type' => $type->id, 'level' => $block->level, 'enabled' => $block->enabled, 'collapsed' => $block->collapsed, 'tabs' => craft()->neo->renderBlockTabs($type, $block, $namespace)]; } $this->returnJson(['success' => true, 'blocks' => $renderedBlocks]); }
public function populateElementModel($row) { return Neo_BlockModel::populateModel($row); }
/** * Builds the HTML for an individual block type. * If you don't pass in a block along with the type, then it'll render a base template to build real blocks from. * If you do pass in a block, then it's current field values will be rendered as well. * * @param Neo_BlockTypeModel $blockType * @param Neo_BlockModel|null $block * @param string $namespace * @param bool|false $static * @param $locale * @return array */ public function renderBlockTabs(Neo_BlockTypeModel $blockType, Neo_BlockModel $block = null, $namespace = '', $static = false, $locale = null) { $oldNamespace = craft()->templates->getNamespace(); $newNamespace = craft()->templates->namespaceInputName($namespace . '[__NEOBLOCK__][fields]', $oldNamespace); craft()->templates->setNamespace($newNamespace); $tabsHtml = []; $fieldLayout = $blockType->getFieldLayout(); $fieldLayoutTabs = $fieldLayout->getTabs(); if (!$block) { // Trick Craft into rendering fields of a block type with the correct locale (see below) $block = new Neo_BlockModel(); } if ($locale) { // Rendering the `_includes/fields` template doesn't take a `locale` parameter, even though individual // field templates do. If no locale is passed when rendering a field (which there won't be when using the // `fields` template) it defaults to the passed element's locale. The following takes advantage of this // by setting the locale on the block itself. In the event that only a block type is being rendered, the // above creates a dummy block to so the locale can be passed. $block->locale = $locale; } foreach ($fieldLayoutTabs as $fieldLayoutTab) { craft()->templates->startJsBuffer(); $tabHtml = ['name' => Craft::t($fieldLayoutTab->name), 'headHtml' => '', 'bodyHtml' => '', 'footHtml' => '', 'errors' => []]; $fieldLayoutFields = $fieldLayoutTab->getFields(); foreach ($fieldLayoutFields as $fieldLayoutField) { $field = $fieldLayoutField->getField(); $fieldType = $field->getFieldType(); if ($fieldType) { $fieldType->element = $block; $fieldType->setIsFresh($block == null); if ($block) { $fieldErrors = $block->getErrors($field->handle); if (!empty($fieldErrors)) { $tabHtml['errors'] = array_merge($tabHtml['errors'], $fieldErrors); } } } } $tabHtml['bodyHtml'] = craft()->templates->namespaceInputs(craft()->templates->render('_includes/fields', ['namespace' => null, 'element' => $block, 'fields' => $fieldLayoutFields, 'static' => $static])); foreach ($fieldLayoutFields as $fieldLayoutField) { $fieldType = $fieldLayoutField->getField()->getFieldType(); if ($fieldType) { $fieldType->setIsFresh(null); } } $tabHtml['footHtml'] = craft()->templates->clearJsBuffer(); $tabsHtml[] = $tabHtml; } craft()->templates->setNamespace($oldNamespace); return $tabsHtml; }