Skip to content

Commit

Permalink
Add post_types field types - Version bump to 3.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Parziale committed Oct 14, 2019
1 parent 3d97101 commit e09b557
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Aeria/Aeria.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
class Aeria extends Container
{
public const VERSION = '3.0.6';
public const VERSION = '3.0.7';
/**
* Constructs the Aeria container
*
Expand Down
57 changes: 57 additions & 0 deletions Aeria/Field/Fields/PostTypesField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Aeria\Field\Fields;

use Aeria\Field\Fields\SelectField;
use Aeria\Field\Interfaces\FieldInterface;
/**
* PostTypesField is the class that represents a select with all post-types as options
*
* @category Field
* @package Aeria
* @author Alberto Parziale <[email protected]>
* @license https://github.com/caffeinalab/aeria/blob/master/LICENSE MIT license
* @link https://github.com/caffeinalab/aeria
*/
class PostTypesField extends SelectField
{

protected $original_config;
/**
* Constructs the field
*
* @param string $parent_key the field's parent key
* @param array $config the field's config
* @param array $sections Aeria's sections config
* @param array $index index for of the subfield
*
* @return void
*
* @access public
* @since Method available since Release 3.0.7
*/
public function __construct($parent_key, $config, $sections, $index = null) {
parent::__construct($parent_key, $config, $sections, $index);

$this->original_config = json_decode(json_encode($config));

$this->config['type'] = 'select';

$this->config['options'] = [
array( 'label' => 'page', 'value' => 'page'),
array( 'label' => 'post', 'value' => 'post'),
];

$post_types = get_post_types(array(
'public' => true,
'_builtin' => false
));

$this->config['options'] = array_merge(
$this->config['options'],
array_map( function ($post_type) {
return array( 'label' => $post_type, 'value' => $post_type);
}, array_values($post_types) )
);
}
}
3 changes: 2 additions & 1 deletion Aeria/Kernel/Tasks/CreateField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Aeria\Kernel\AbstractClasses\Task;
/**
* This task is in charge of creating fields.
*
*
* @category Kernel
* @package Aeria
* @author Simone Montali <[email protected]>
Expand Down Expand Up @@ -36,6 +36,7 @@ public function do(array $args)
$args['service']['field']->register('select', \Aeria\Field\Fields\SelectField::class);
$args['service']['field']->register('switch', \Aeria\Field\Fields\SwitchField::class);
$args['service']['field']->register('relation', \Aeria\Field\Fields\RelationField::class);
$args['service']['field']->register('post_types', \Aeria\Field\Fields\PostTypesField::class);
$args['service']['field']->register('maps', \Aeria\Field\Fields\MapField::class);
$args['service']['field']->register('daterange', \Aeria\Field\Fields\DateRangeField::class);
// example of multiple registered fields with the same handler; not
Expand Down
2 changes: 1 addition & 1 deletion aeria.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Aeria
* Plugin URI: https://github.com/caffeinalab/aeria
* Description: Aeria is a modular, lightweight, fast WordPress Application development kit.
* Version: 3.0.6
* Version: 3.0.7
* Author: Caffeina
* Author URI: https://caffeina.com
* Text Domain: aeria
Expand Down

0 comments on commit e09b557

Please sign in to comment.