Created
July 30, 2015 12:33
-
-
Save jenstornell/e4a4c0a372a7e5d8bc03 to your computer and use it in GitHub Desktop.
Add it to fields/transparent/transparent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class TransparentField extends BaseField{ | |
private $fields = null; | |
private $hidden = 0; | |
private $hidden_empty = 0; | |
public function __construct() { | |
$this->type = 'transparent'; | |
} | |
public function init() { | |
$this->fields = $this->fields(); | |
$this->hidden(); | |
$this->values(); | |
} | |
public function content() { | |
$this->init(); | |
$hidden = brick('div')->append( brick('strong')->append('Hidden fields: ') . $this->hidden . ' / ' . size( $this->fields ) ); | |
$empty = brick('div')->append( brick('strong')->append('Hidden empty fields: ') . $this->hidden_empty . ' / ' . $this->hidden ); | |
$html = $hidden . $empty; | |
return $html; | |
} | |
public function fields() { | |
$blueprint = kirby()->roots->blueprints() . DS . $this->page()->template() . '.php'; | |
$fields = Yaml::read( $blueprint )['fields']; | |
return $fields; | |
} | |
public function hidden() { | |
foreach( $this->fields as $name => $field ) { | |
$type = $field['type']; | |
$value = $this->page()->content()->get($name)->value(); | |
if( $type == 'hidden' ) { | |
$this->hidden++; | |
if( $value == '' ) { | |
$this->hidden_empty++; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment