Skip to content

Commit

Permalink
Fixes replication logic for syntax models
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed May 29, 2024
1 parent e196770 commit 5879adb
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/Parse/Syntax/SyntaxModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/
trait SyntaxModelTrait
{
/**
* @deprecated replace with initializeSyntaxModelTrait model.afterFetch
*/
public static function bootSyntaxModelTrait()
{
static::fetched(function ($model) {
Expand All @@ -18,9 +21,18 @@ public static function bootSyntaxModelTrait()
}

/**
* Defines any relationships (attachments) that this model will need
* based on the field definitions.
* @return void
* initializeSyntaxModelTrait constructor
*/
public function initializeSyntaxModelTrait()
{
$this->bindEvent('model.beforeReplicate', function() {
$this->defineSyntaxRelations();
});
}

/**
* defineSyntaxRelations defines any relationships (attachments) that this model
* will need based on the field definitions.
*/
public function defineSyntaxRelations()
{
Expand Down Expand Up @@ -98,8 +110,8 @@ protected function getThumbForImage($image, $params = [])
}

/**
* Prepare the syntax fields for use in a Form builder. The array
* name is added to each field.
* getFormSyntaxFields prepares the syntax fields for use in a Form builder.
* The array name is added to each field.
* @return array
*/
public function getFormSyntaxFields()
Expand Down Expand Up @@ -134,7 +146,7 @@ public function getFormSyntaxFields()
}

/**
* Processes supplied content and extracts the field definitions
* makeSyntaxFields processes supplied content and extracts the field definitions
* and default data. It is mixed with the current data and applied
* to the fields and data attributes.
* @param string $content
Expand All @@ -147,9 +159,7 @@ public function makeSyntaxFields($content)

$this->setAttribute($this->getSyntaxFieldsColumnName(), $fields);

/*
* Remove fields no longer present and add default values
*/
// Remove fields no longer present and add default values
$currentFields = array_intersect_key((array) $this->getFormSyntaxData(), $parser->getFieldValues());
$currentFields = $currentFields + $parser->getFieldValues();

Expand All @@ -158,13 +168,16 @@ public function makeSyntaxFields($content)
return $fields;
}

/**
* getSyntaxParser
*/
public function getSyntaxParser($content)
{
return Parser::parse($content);
}

/**
* Get data column name.
* getSyntaxDataColumnName returns the data column name.
* @return string
*/
public function getSyntaxDataColumnName()
Expand All @@ -173,7 +186,7 @@ public function getSyntaxDataColumnName()
}

/**
* Get value of the model syntax_data column.
* getSyntaxData returns value of the model syntax_data column.
* @return int
*/
public function getSyntaxData()
Expand All @@ -182,7 +195,7 @@ public function getSyntaxData()
}

/**
* Get fields column name.
* getSyntaxFieldsColumnName returns fields column name.
* @return string
*/
public function getSyntaxFieldsColumnName()
Expand All @@ -191,7 +204,7 @@ public function getSyntaxFieldsColumnName()
}

/**
* Get value of the model syntax_fields column.
* getSyntaxFields returns value of the model syntax_fields column.
* @return int
*/
public function getSyntaxFields()
Expand Down

0 comments on commit 5879adb

Please sign in to comment.