function ResourceTypeBuildEvent::setPublicFieldName

Same name in other branches
  1. 9 core/modules/jsonapi/src/ResourceType/ResourceTypeBuildEvent.php \Drupal\jsonapi\ResourceType\ResourceTypeBuildEvent::setPublicFieldName()
  2. 8.9.x core/modules/jsonapi/src/ResourceType/ResourceTypeBuildEvent.php \Drupal\jsonapi\ResourceType\ResourceTypeBuildEvent::setPublicFieldName()
  3. 11.x core/modules/jsonapi/src/ResourceType/ResourceTypeBuildEvent.php \Drupal\jsonapi\ResourceType\ResourceTypeBuildEvent::setPublicFieldName()

Sets the public name of the given field on the resource type to be built.

Parameters

\Drupal\jsonapi\ResourceType\ResourceTypeField $field: The field for which to set a public name.

string $public_field_name: The public field name to set.

File

core/modules/jsonapi/src/ResourceType/ResourceTypeBuildEvent.php, line 130

Class

ResourceTypeBuildEvent
An event used to configure the construction of a JSON:API resource type.

Namespace

Drupal\jsonapi\ResourceType

Code

public function setPublicFieldName(ResourceTypeField $field, $public_field_name) {
    foreach ($this->fields as $index => $value) {
        if ($field === $value) {
            $this->fields[$index] = $value->withPublicName($public_field_name);
            return;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.