public function validateBlock(SuperTable_BlockModel $block)
 {
     $block->clearErrors();
     $blockRecord = $this->_getBlockRecord($block);
     $blockRecord->fieldId = $block->fieldId;
     $blockRecord->ownerId = $block->ownerId;
     $blockRecord->typeId = $block->typeId;
     $blockRecord->sortOrder = $block->sortOrder;
     $blockRecord->validate();
     $block->addErrors($blockRecord->getErrors());
     $originalFieldContext = craft()->content->fieldContext;
     craft()->content->fieldContext = 'superTableBlockType:' . $block->typeId;
     if (!craft()->content->validateContent($block)) {
         $block->addErrors($block->getContent()->getErrors());
     }
     craft()->content->fieldContext = $originalFieldContext;
     return !$block->hasErrors();
 }
 public function populateElementModel($row)
 {
     return SuperTable_BlockModel::populateModel($row);
 }
 private function _getBlockTypeInfoForInput($name)
 {
     $settings = $this->getSettings();
     $blockType = array();
     // Set a temporary namespace for these
     $originalNamespace = craft()->templates->getNamespace();
     $namespace = craft()->templates->namespaceInputName($name . '[__BLOCK_ST__][fields]', $originalNamespace);
     craft()->templates->setNamespace($namespace);
     foreach ($settings->getBlockTypes() as $blockType) {
         // Create a fake SuperTable_BlockModel so the field types have a way to get at the owner element, if there is one
         $block = new SuperTable_BlockModel();
         $block->fieldId = $this->model->id;
         $block->typeId = $blockType->id;
         if ($this->element) {
             $block->setOwner($this->element);
             $block->locale = $this->element->locale;
         }
         $fieldLayoutFields = $blockType->getFieldLayout()->getFields();
         foreach ($fieldLayoutFields as $fieldLayoutField) {
             $fieldType = $fieldLayoutField->getField()->getFieldType();
             if ($fieldType) {
                 $fieldType->element = $block;
                 $fieldType->setIsFresh(true);
             }
         }
         craft()->templates->startJsBuffer();
         $bodyHtml = craft()->templates->namespaceInputs(craft()->templates->render('supertable/fields', array('namespace' => null, 'fields' => $fieldLayoutFields, 'settings' => $settings)));
         // Reset $_isFresh's
         foreach ($fieldLayoutFields as $fieldLayoutField) {
             $fieldType = $fieldLayoutField->getField()->getFieldType();
             if ($fieldType) {
                 $fieldType->setIsFresh(null);
             }
         }
         $footHtml = craft()->templates->clearJsBuffer();
         $blockType = array('type' => $blockType->id, 'bodyHtml' => $bodyHtml, 'footHtml' => $footHtml);
     }
     craft()->templates->setNamespace($originalNamespace);
     return $blockType;
 }