-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add post_types field types - Version bump to 3.0.7
- Loading branch information
Alberto Parziale
committed
Oct 14, 2019
1 parent
3d97101
commit e09b557
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
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
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
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) ) | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
|
@@ -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 | ||
|
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