PHP Class Craft\NeoService

Inheritance: extends craft\BaseApplicationComponent
Datei anzeigen Open project: benjamminf/craft-neo

Public Properties

Property Type Description
$currentSavingBlockType Neo_BlockTypeModel | null

Public Methods

Method Description
deleteBlockById ( array\int $blockIds ) : boolean Deletes a block (or series of blocks) by it's ID from the database.
deleteBlockType ( Neo_BlockTypeModel $blockType ) : boolean Deletes a block type from the database.
deleteField ( craft\FieldModel $neoField ) Deletes a Neo field from the database.
deleteGroupsByFieldId ( $fieldId ) : boolean Deletes all groups associated with a field from the database.
deleteStructure ( NeoFieldType $fieldType ) : boolean Deletes the structure for a field from the database.
getBlockById ( integer $blockId, integer | null $localeId = null ) : Neo_BlockModel Returns a block given it's ID.
getBlockTypeById ( $blockTypeId ) : Neo_BlockTypeModel Finds a block type by it's ID.
getBlockTypesByFieldId ( $fieldId, string | null $indexBy = null ) : array Returns a list of block types associated with a field.
getBlocks ( integer $fieldId, integer $ownerId, string | null $locale = null ) : array
getCriteria ( mixed | null $attributes = null ) : Neo_CriteriaModel Creates a Neo-specific element criteria model.
getGroupsByFieldId ( $fieldId, string | null $indexBy = null ) : array Returns a list of groups associated with a field.
getStructure ( NeoFieldType $fieldType ) : craft\StructureModel | boolean Returns the structure for a field.
isPreviewMode ( ) : boolean Checks the current route/environment to see if database calls for Neo blocks should be avoided.
renderBlockTabs ( Neo_BlockTypeModel $blockType, Neo_BlockModel $block = null, string $namespace = '', boolean | false $static = false, $locale = null ) : array Builds the HTML for an individual block type.
requirePlugin ( $plugin ) Forces a plugin to exist by throwing an error if it doesn't.
saveBlock ( Neo_BlockModel $block, boolean | true $validate = true ) : boolean Saves a block to the database.
saveBlockCollapse ( Neo_BlockModel $block ) : boolean Saves a block's expansion state to the database.
saveBlockType ( Neo_BlockTypeModel $blockType, boolean | true $validate = true ) : boolean Saves a block type to the database.
saveFieldValue ( NeoFieldType $fieldType ) Saves a Neo field's value to the database.
saveGroup ( Neo_GroupModel $group ) : boolean Saves a group to the database.
saveSettings ( Neo_SettingsModel $settings, boolean | true $validate = true ) : boolean Saves a field's settings to the database.
saveStructure ( craft\StructureModel $structure, NeoFieldType $fieldType ) : boolean Saves the structure for a field to the database.
validateBlock ( Neo_BlockModel $block ) : boolean Runs validation on a block, and saves any errors to the block.
validateBlockType ( Neo_BlockTypeModel $blockType, boolean | true $validateUniques = true ) : boolean Runs validation on a block type, and saves any errors to the block type.
validateFieldSettings ( Neo_SettingsModel $settings ) : boolean Validates a field's settings, loading the settings and block type models with any error messages.

Protected Methods

Method Description
beginTransaction ( ) : CDbTransaction | null Returns a new database transaction if one hasn't already been created.
commitTransaction ( CDbTransaction $transaction ) Commits a database transaction if transaction is not null.
rollbackTransaction ( CDbTransaction $transaction ) Rolls back a database transaction if transaction is not null.

Private Methods

Method Description
_applyFieldTranslationSetting ( $owner, $field, $blocks ) Applies a field's translation setting to any existing values of the field.
_createBlockTypeQuery ( ) : mixed Creates a base database query for all block types.
_createGroupQuery ( ) : mixed Creates a base database query for all groups.
_getBlockRecord ( Neo_BlockModel $block ) : Neo_BlockRecord Finds and returns the block record from a block model.
_getBlockTypeRecord ( Neo_BlockTypeModel $blockType ) : Neo_BlockTypeRecord Finds and returns the block type record from a block type model.
_getFieldLocale ( NeoFieldType $fieldType ) : string | null Returns the locale for a given field if it's set to be translatable, otherwise returns null.
_indexBy ( $list, $property ) : array Changes how an array is indexed based on it's containing objects properties.

Method Details

beginTransaction() protected method

Returns a new database transaction if one hasn't already been created.
protected beginTransaction ( ) : CDbTransaction | null
return CDbTransaction | null

commitTransaction() protected method

Commits a database transaction if transaction is not null.
protected commitTransaction ( CDbTransaction $transaction )
$transaction CDbTransaction

deleteBlockById() public method

Deletes a block (or series of blocks) by it's ID from the database.
public deleteBlockById ( array\int $blockIds ) : boolean
$blockIds array\int
return boolean

deleteBlockType() public method

Deletes a block type from the database.
public deleteBlockType ( Neo_BlockTypeModel $blockType ) : boolean
$blockType Neo_BlockTypeModel
return boolean

deleteField() public method

Deletes a Neo field from the database.
public deleteField ( craft\FieldModel $neoField )
$neoField craft\FieldModel

deleteGroupsByFieldId() public method

Deletes all groups associated with a field from the database.
public deleteGroupsByFieldId ( $fieldId ) : boolean
$fieldId
return boolean

deleteStructure() public method

Deletes the structure for a field from the database.
public deleteStructure ( NeoFieldType $fieldType ) : boolean
$fieldType NeoFieldType
return boolean

getBlockById() public method

Returns a block given it's ID.
public getBlockById ( integer $blockId, integer | null $localeId = null ) : Neo_BlockModel
$blockId integer
$localeId integer | null
return Neo_BlockModel

getBlockTypeById() public method

Finds a block type by it's ID.
public getBlockTypeById ( $blockTypeId ) : Neo_BlockTypeModel
$blockTypeId
return Neo_BlockTypeModel

getBlockTypesByFieldId() public method

Returns a list of block types associated with a field.
public getBlockTypesByFieldId ( $fieldId, string | null $indexBy = null ) : array
$fieldId
$indexBy string | null
return array

getBlocks() public method

public getBlocks ( integer $fieldId, integer $ownerId, string | null $locale = null ) : array
$fieldId integer
$ownerId integer
$locale string | null
return array

getCriteria() public method

Creates a Neo-specific element criteria model.
public getCriteria ( mixed | null $attributes = null ) : Neo_CriteriaModel
$attributes mixed | null
return Neo_CriteriaModel

getGroupsByFieldId() public method

Returns a list of groups associated with a field.
public getGroupsByFieldId ( $fieldId, string | null $indexBy = null ) : array
$fieldId
$indexBy string | null
return array

getStructure() public method

Returns the structure for a field.
public getStructure ( NeoFieldType $fieldType ) : craft\StructureModel | boolean
$fieldType NeoFieldType
return craft\StructureModel | boolean

isPreviewMode() public method

This is so that live preview and entry drafts can use their data instead.
public isPreviewMode ( ) : boolean
return boolean

renderBlockTabs() public method

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.
public renderBlockTabs ( Neo_BlockTypeModel $blockType, Neo_BlockModel $block = null, string $namespace = '', boolean | false $static = false, $locale = null ) : array
$blockType Neo_BlockTypeModel
$block Neo_BlockModel
$namespace string
$static boolean | false
$locale
return array

requirePlugin() public method

Used when supporting other plugins, such as Relabel and Reasons.
public requirePlugin ( $plugin )
$plugin

rollbackTransaction() protected method

Rolls back a database transaction if transaction is not null.
protected rollbackTransaction ( CDbTransaction $transaction )
$transaction CDbTransaction

saveBlock() public method

Saves a block to the database.
public saveBlock ( Neo_BlockModel $block, boolean | true $validate = true ) : boolean
$block Neo_BlockModel
$validate boolean | true
return boolean

saveBlockCollapse() public method

It bypasses the elements system and performs a direct database query. This is so it doesn't cause caches to be regenerated. It's also more performant, which comes in handy when this is called in AJAX requests.
public saveBlockCollapse ( Neo_BlockModel $block ) : boolean
$block Neo_BlockModel
return boolean

saveBlockType() public method

Saves a block type to the database.
public saveBlockType ( Neo_BlockTypeModel $blockType, boolean | true $validate = true ) : boolean
$blockType Neo_BlockTypeModel
$validate boolean | true
return boolean

saveFieldValue() public method

Saves a Neo field's value to the database.
public saveFieldValue ( NeoFieldType $fieldType )
$fieldType NeoFieldType

saveGroup() public method

Saves a group to the database.
public saveGroup ( Neo_GroupModel $group ) : boolean
$group Neo_GroupModel
return boolean

saveSettings() public method

Saves a field's settings to the database.
public saveSettings ( Neo_SettingsModel $settings, boolean | true $validate = true ) : boolean
$settings Neo_SettingsModel
$validate boolean | true
return boolean

saveStructure() public method

Saves the structure for a field to the database.
public saveStructure ( craft\StructureModel $structure, NeoFieldType $fieldType ) : boolean
$structure craft\StructureModel
$fieldType NeoFieldType
return boolean

validateBlock() public method

Runs validation on a block, and saves any errors to the block.
public validateBlock ( Neo_BlockModel $block ) : boolean
$block Neo_BlockModel
return boolean

validateBlockType() public method

Runs validation on a block type, and saves any errors to the block type.
public validateBlockType ( Neo_BlockTypeModel $blockType, boolean | true $validateUniques = true ) : boolean
$blockType Neo_BlockTypeModel
$validateUniques boolean | true
return boolean

validateFieldSettings() public method

Validates a field's settings, loading the settings and block type models with any error messages.
public validateFieldSettings ( Neo_SettingsModel $settings ) : boolean
$settings Neo_SettingsModel
return boolean

Property Details

$currentSavingBlockType public_oe property

public Neo_BlockTypeModel,craft|null $currentSavingBlockType
return Neo_BlockTypeModel | null