This repository was archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
7.x 2.x typed data
Andy Truong edited this page Mar 17, 2014
·
2 revisions
TypedData API was built to helper developer validate input value must match its schema:
- any
- boolean
- constant
- string
- function
- integer
- list
- list<sub_type>
- mapping
Validate a list<string> typed-data:
<?php
$schema = array('type' => 'list<string>');
$input = array('one', 'two', 'three');
$data = at_data($schema, $input);
// Validate
echo $data->validate($error) ? $data->getValue() : $error;Validate & compute a mapping typed-data:
<?php
$def = array(
'type' => 'mapping',
'mapping' => array(
'title' => array('type' => 'string'),
'access arguments' => array('type' => 'list<string>'),
'page callback' => array('type' => 'function'),
'page arguments' => array('type' => 'list<string>'),
'type' => array('type' => 'constant'),
)
);
$input = array(
'title' => 'Menu item',
'access arguments' => array('access content'),
'page callback' => 't',
'page arguments' => array('Drupal'),
'type' => 'MENU_NORMAL_ITEM',
);
$data = at_data($def, $input);
if ($data->validate($error)) {
$result = $data->getValue();
}
else {
echo $error;
} ___ ___________ _ _
/ _ \_ _| ___ \ | | | |
/ /_\ \| | | |_/ / __ _ ___ ___ _ __ ___ ___ __| |_ _| | ___
| _ || | | ___ \/ _` / __|/ _ \ | '_ ` _ \ / _ \ / _` | | | | |/ _ \
| | | || | | |_/ / (_| \__ \ __/_| | | | | | (_) | (_| | |_| | | __/
\_| |_/\_/ \____/ \__,_|___/\___(_)_| |_| |_|\___/ \__,_|\__,_|_|\___|
- Caching
- Twig template
- twig Service
- twig_string Service
- Recipes
- Extends
- Easy Block
- Easy Routing
- Easy Breadcrumb
- Entity Template
- Drush Commands:
- Functions:
- Misc
- Status
- Tools for Development enviroment
- /devel/php improved
- /at/sql
- /at/twig
- Kint integration