Skip to content

Commit

Permalink
[Fixed] Fixed an issue with the 'custom' data not displaying in SEOma…
Browse files Browse the repository at this point in the history
…tic Meta FieldTypes
  • Loading branch information
khalwat committed Jun 27, 2016
1 parent 2f9da9f commit 28678bf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ Some things to do, and ideas for potential features:

## Changelog

### 1.1.21 -- 2016.06.27
### 1.1.22 -- 2016.06.27

* [Fixed] Fixed the variable accessor rountines getSocial() and getIdentity()
* [Fixed] Fixed an issue with the 'custom' data not displaying in SEOmatic Meta FieldTypes
* [Improved] Updated the README.md

### 1.1.21 -- 2016.06.25
Expand Down
48 changes: 29 additions & 19 deletions fieldtypes/Seomatic_MetaFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ public function prepValueFromPost($value)
else
{
$result = new Seomatic_MetaFieldModel($value);
$result = $this->prepValue($result);
}
return $result;
}
Expand All @@ -281,14 +282,17 @@ public function prepValue($value)
$value = new Seomatic_MetaFieldModel();

$value->seoTitle = $this->getSettings()->seoTitle;
$value->seoTitleUnparsed = $this->getSettings()->seoTitle;
$value->seoTitleSource = $this->getSettings()->seoTitleSource;
$value->seoTitleSourceField = $this->getSettings()->seoTitleSourceField;

$value->seoDescription = $this->getSettings()->seoDescription;
$value->seoDescriptionUnparsed = $this->getSettings()->seoDescription;
$value->seoDescriptionSource = $this->getSettings()->seoDescriptionSource;
$value->seoDescriptionSourceField = $this->getSettings()->seoDescriptionSourceField;

$value->seoKeywords = $this->getSettings()->seoKeywords;
$value->seoKeywordsUnparsed = $this->getSettings()->seoKeywords;
$value->seoKeywordsSource = $this->getSettings()->seoKeywordsSource;
$value->seoKeywordsSourceField = $this->getSettings()->seoKeywordsSourceField;

Expand All @@ -304,67 +308,73 @@ public function prepValue($value)
/* -- Handle pulling values from other fields */

$element = $this->element;
$entryMeta = $value;
if ($value->seoTitleUnparsed == "")
$value->seoTitleUnparsed = $value->seoTitle;
if ($value->seoDescriptionUnparsed == "")
$value->seoDescriptionUnparsed = $value->seoDescription;
if ($value->seoKeywordsUnparsed == "")
$value->seoKeywordsUnparsed = $value->seoKeywords;

if ($element)
{
/* -- Swap in any SEOmatic fields that are pulling from other entry fields */

switch ($entryMeta->seoTitleSource)
switch ($value->seoTitleSource)
{
case 'field':
if (isset($element[$entryMeta->seoTitleSourceField]))
if (isset($element[$value->seoTitleSourceField]))
{
$entryMeta->seoTitle = craft()->seomatic->getTextFromEntryField($element[$entryMeta->seoTitleSourceField]);
$value->seoTitle = craft()->seomatic->getTextFromEntryField($element[$value->seoTitleSourceField]);
}
break;

case 'custom':
$entryMeta->seoTitle = craft()->seomatic->parseAsTemplate($entryMeta->seoTitle, $element);
$value->seoTitle = craft()->seomatic->parseAsTemplate($value->seoTitleUnparsed, $element);
break;
}

switch ($entryMeta->seoDescriptionSource)
switch ($value->seoDescriptionSource)
{
case 'field':
if (isset($element[$entryMeta->seoDescriptionSourceField]))
if (isset($element[$value->seoDescriptionSourceField]))
{
$entryMeta->seoDescription = craft()->seomatic->getTextFromEntryField($element[$entryMeta->seoDescriptionSourceField]);
$value->seoDescription = craft()->seomatic->getTextFromEntryField($element[$value->seoDescriptionSourceField]);
}
break;

case 'custom':
$entryMeta->seoDescription = craft()->seomatic->parseAsTemplate($entryMeta->seoDescription, $element);
$value->seoDescription = craft()->seomatic->parseAsTemplate($value->seoDescriptionUnparsed, $element);
break;
}

switch ($entryMeta->seoKeywordsSource)
switch ($value->seoKeywordsSource)
{
case 'field':
if (isset($element[$entryMeta->seoKeywordsSourceField]))
if (isset($element[$value->seoKeywordsSourceField]))
{
$entryMeta->seoKeywords = craft()->seomatic->getTextFromEntryField($element[$entryMeta->seoKeywordsSourceField]);
$value->seoKeywords = craft()->seomatic->getTextFromEntryField($element[$value->seoKeywordsSourceField]);
}
break;

case 'keywords':
if (isset($element[$entryMeta->seoKeywordsSourceField]))
if (isset($element[$value->seoKeywordsSourceField]))
{
$text = craft()->seomatic->getTextFromEntryField($element[$entryMeta->seoKeywordsSourceField]);
$entryMeta->seoKeywords = craft()->seomatic->extractKeywords($text);
$text = craft()->seomatic->getTextFromEntryField($element[$value->seoKeywordsSourceField]);
$value->seoKeywords = craft()->seomatic->extractKeywords($text);
}
break;

case 'custom':
$entryMeta->seoKeywords = craft()->seomatic->parseAsTemplate($entryMeta->seoKeywords, $element);
$value->seoKeywords = craft()->seomatic->parseAsTemplate($value->seoKeywordsUnparsed, $element);
break;
}

switch ($entryMeta->seoImageIdSource)
switch ($value->seoImageIdSource)
{
case 'field':
if (isset($element[$entryMeta->seoImageIdSourceField]) && $element[$entryMeta->seoImageIdSourceField]->first())
if (isset($element[$value->seoImageIdSourceField]) && $element[$value->seoImageIdSourceField]->first())
{
$entryMeta->seoImageId = $element[$entryMeta->seoImageIdSourceField]->first()->id;
$value->seoImageId = $element[$value->seoImageIdSourceField]->first()->id;
}
break;
}
Expand Down
3 changes: 3 additions & 0 deletions models/Seomatic_MetaFieldModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Seomatic_MetaFieldModel extends Seomatic_MetaModel
protected function defineAttributes()
{
return array_merge(parent::defineAttributes(), array(
'seoTitleUnparsed' => array(AttributeType::String, 'default' => ''),
'seoDescriptionUnparsed' => array(AttributeType::String, 'default' => ''),
'seoKeywordsUnparsed' => array(AttributeType::String, 'default' => ''),
'seoTitleSource' => array(AttributeType::Enum, 'values' => "custom,field", 'default' => 'field'),
'seoTitleSourceField' => array(AttributeType::String, 'default' => 'title'),
'seoDescriptionSource' => array(AttributeType::Enum, 'values' => "custom,field", 'default' => 'custom'),
Expand Down
1 change: 1 addition & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"date": "2016-06-27T11:00:00-11:00",
"notes": [
"[Fixed] Fixed the variable accessor rountines getSocial() and getIdentity()",
"[Fixed] Fixed an issue with the 'custom' data not displaying in SEOmatic Meta FieldTypes",
"[Improved] Updated the README.md"
]
},
Expand Down
2 changes: 2 additions & 0 deletions services/SeomaticService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,9 @@ function parseAsTemplate($templateStr, $element)
catch (\Exception $e)
{
SeomaticPlugin::log("Template error in the `" . $templateStr . "` template.", LogLevel::Info, true);
$result = $templateStr;
}
return $result;
} /* -- parseAsTemplate */

/* --------------------------------------------------------------------------------
Expand Down
18 changes: 9 additions & 9 deletions templates/field.twig
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
fieldClass: 'nomarginfield',
id: id ~ 'seoTitle',
class: 'nicetext',
name: name ~ '[seoTitle]',
value: meta.seoTitle,
errors: meta.getErrors('seoTitle'),
name: name ~ '[seoTitleUnparsed]',
value: meta.seoTitleUnparsed,
errors: meta.getErrors('seoTitleUnparsed'),
maxlength: titleLength,
showCharsLeft: true,
required: false,
Expand Down Expand Up @@ -124,9 +124,9 @@
id: id ~ 'seoDescription',
fieldClass: 'nomarginfield',
class: 'nicetext',
name: name ~ '[seoDescription]',
value: meta.seoDescription,
errors: meta.getErrors('seoDescription'),
name: name ~ '[seoDescriptionUnparsed]',
value: meta.seoDescriptionUnparsed,
errors: meta.getErrors('seoDescriptionUnparsed'),
maxlength: 160,
showCharsLeft: true,
required: false,
Expand Down Expand Up @@ -180,9 +180,9 @@
{{ forms.textarea({
id: id ~ 'seoKeywords',
class: 'nicetext',
name: name ~ '[seoKeywords]',
value: meta.seoKeywords,
errors: meta.getErrors('seoKeywords'),
name: name ~ '[seoKeywordsUnparsed]',
value: meta.seoKeywordsUnparsed,
errors: meta.getErrors('seoKeywordsUnparsed'),
maxlength: 200,
showCharsLeft: true,
required: false,
Expand Down

0 comments on commit 28678bf

Please sign in to comment.