Skip to content

Commit

Permalink
Merge pull request #11 from lukeyouell/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
lukeyouell authored Jul 31, 2018
2 parents f649ce9 + 3f8df37 commit 3ae4b36
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## 1.4.0 - 2018-07-31

### Added
- Super Table support 🎉

## 1.3.0 - 2018-06-22

### Added
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,4 @@ return [

Some things to do, and ideas for potential features:

- SuperTable integration

Brought to you by [Luke Youell](https://github.com/lukeyouell)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lukeyouell/craft-readtime",
"description": "Calculate the estimated read time for content.",
"type": "craft-plugin",
"version": "1.3.0",
"version": "1.4.0",
"keywords": [
"craft",
"cms",
Expand Down
32 changes: 27 additions & 5 deletions src/twigextensions/ReadTimeTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,42 @@ public function readTimeFunction($element, $showSeconds = true)
foreach ($element->getFieldLayout()->getFields() as $field) {
try {
// If field is a matrix then loop through fields in block
if ($field instanceof craft\fields\Matrix) {
if ($field instanceof \craft\fields\Matrix) {
foreach($element->getFieldValue($field->handle)->all() as $block) {
$blockFields = $block->getFieldLayout()->getFields();

foreach($blockFields as $blockField){
foreach ($blockFields as $blockField) {
$value = $block->getFieldValue($blockField->handle);
$seconds = $this->valToSeconds($value);
$totalSeconds = $totalSeconds + $seconds;
}
}
} elseif($field instanceof \verbb\supertable\fields\SuperTableField) {
foreach($element->getFieldValue($field->handle)->all() as $block) {
$blockFields = $block->getFieldLayout()->getFields();

foreach ($blockFields as $blockField) {
if ($blockField instanceof \craft\fields\Matrix) {
foreach($block->getFieldValue($blockField->handle)->all() as $matrix) {
$matrixFields = $matrix->getFieldLayout()->getFields();

foreach ($matrixFields as $matrixField) {
$value = $matrix->getFieldValue($matrixField->handle);
$seconds = $this->valToSeconds($value);
$totalSeconds = $totalSeconds + $seconds;
}
}
} else {
$value = $block->getFieldValue($blockField->handle);
$seconds = $this->valToSeconds($value);
$totalSeconds = $totalSeconds + $seconds;
}
}
}
} else {
$value = $element->getFieldValue($field->handle);
$seconds = $this->valToSeconds($value);
$totalSeconds = $totalSeconds + $seconds;
$value = $element->getFieldValue($field->handle);
$seconds = $this->valToSeconds($value);
$totalSeconds = $totalSeconds + $seconds;
}
} catch (ErrorException $e) {
continue;
Expand Down

0 comments on commit 3ae4b36

Please sign in to comment.