Skip to content

Instantly share code, notes, and snippets.

@jenstornell
Created July 30, 2015 12:33
Show Gist options
  • Save jenstornell/e4a4c0a372a7e5d8bc03 to your computer and use it in GitHub Desktop.
Save jenstornell/e4a4c0a372a7e5d8bc03 to your computer and use it in GitHub Desktop.
Add it to fields/transparent/transparent.php
<?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