Skip to content

Instantly share code, notes, and snippets.

@jenstornell
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenstornell/8ac77ebfae767eee49db to your computer and use it in GitHub Desktop.
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
<?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