Last active
August 29, 2015 14:26
-
-
Save jenstornell/8ac77ebfae767eee49db to your computer and use it in GitHub Desktop.
Add it to fields/transparent/transparent.php. Add it to the blueprint with type: transparent
This file contains hidden or 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