TestArticles__1_0.php in RESTful 7.2
File
tests/modules/restful_test/src/Plugin/resource/node/test_article/v1/TestArticles__1_0.php
View source
<?php
namespace Drupal\restful_test\Plugin\resource\node\test_article\v1;
use Drupal\restful\Plugin\resource\DataInterpreter\DataInterpreterInterface;
use Drupal\restful\Plugin\resource\Field\ResourceFieldInterface;
use Drupal\restful\Plugin\resource\ResourceInterface;
use Drupal\restful\Plugin\resource\ResourceNode;
class TestArticles__1_0 extends ResourceNode implements ResourceInterface {
protected function publicFields() {
$public_fields = parent::publicFields();
if (!module_exists('entity_validator')) {
return $public_fields;
}
$public_fields['title'] = $public_fields['label'];
$public_fields['body'] = array(
'property' => 'body',
'sub_property' => 'value',
);
return $public_fields;
}
protected function processPublicFields(array $field_definitions) {
$field_definitions = parent::processPublicFields($field_definitions);
if (!($altered_public_name = variable_get('restful_test_revoke_public_field_access'))) {
return $field_definitions;
}
foreach ($field_definitions as $public_name => &$field_definition) {
if ($public_name != $altered_public_name) {
continue;
}
$field_definition['access_callbacks'] = array(
array(
$this,
'publicFieldAccessFalse',
),
);
}
return $field_definitions;
}
public static function publicFieldAccessFalse($op, ResourceFieldInterface $resource_field, DataInterpreterInterface $interpreter) {
return $interpreter
->getWrapper()
->label() == 'access' ? \Drupal\restful\Plugin\resource\Field\ResourceFieldBase::ACCESS_ALLOW : \Drupal\restful\Plugin\resource\Field\ResourceFieldBase::ACCESS_DENY;
}
}