Skip to content

Commit

Permalink
Merge pull request #62 from gigabit-gmbh/repeater_og_image
Browse files Browse the repository at this point in the history
Get a og:image from repeater field type
  • Loading branch information
bobdenotter authored Nov 2, 2017
2 parents fd5abdf + a5b0eef commit 7ea8c3d
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/SEO.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,24 +327,44 @@ private function findImage()
* Helper function for findImage()
*
* @param string $fieldname
* @param string $field
* @param string $imageField
*
* @return string
*/
private function findImageHelper($fieldname)
private function findImageHelper($fieldname, $field = null, $imageField = null)
{
$field = $this->record->contenttype['fields'][$fieldname];
if($field === null){
$field = $this->record->contenttype['fields'][$fieldname];
}

$image = '';

if ($field['type'] == 'image') {
$field = $this->record->values[$fieldname];
if (isset($field['file'])) {
$image = $field['file'];
} elseif (!is_array($field)) {
$image = $field;
if($imageField === null){
$imageField = $this->record->values[$fieldname];
}
if (isset($imageField['file'])) {
$image = $imageField['file'];
} elseif (!is_array($imageField)) {
$image = $imageField;
}
} elseif ($field['type'] == 'imagelist') {
if (isset($field[0]['filename'])) {
$image = $field[0]['filename'];
}
} elseif ($field['type'] == 'repeater'){
// check repeating items, too
if($this->record->values[$fieldname] instanceof RepeatingFieldCollection){
foreach($this->record->values[$fieldname]->flatten() as $repeatField){
$fieldArray = $repeatField->serialize();
$fieldArray['type'] = $fieldArray['fieldtype']; // type matching
$image = $this->findImageHelper($repeatField->getName(), $fieldArray, $repeatField->getValue());
if(empty($image) === false){
return $image;
}
}
}
}

return $image;
Expand Down

0 comments on commit 7ea8c3d

Please sign in to comment.