You are here

public function App::set in Apigee Edge 8

Sets a field value.

Parameters

string $field_name: The name of the field to set; e.g., 'title' or 'name'.

mixed $value: The value to set, or NULL to unset the field.

bool $notify: (optional) Whether to notify the entity of the change. Defaults to TRUE. If the update stems from the entity, set it to FALSE to avoid being notified again.

Return value

$this

Throws

\InvalidArgumentException If the specified field does not exist.

Overrides FieldableEdgeEntityBase::set

File

src/Entity/App.php, line 414

Class

App
Base class for App Drupal entities.

Namespace

Drupal\apigee_edge\Entity

Code

public function set($field_name, $value, $notify = TRUE) {

  // If the callback URL value is not a valid URL then save an empty string
  // as the field value and set the callbackUrl property to the original
  // value. (So we can display the original (invalid URL) on the edit form.)
  // This trick is not necessary if the value's type is array because in this
  // case the field value is set on the developer app edit form.
  if ($field_name === 'callbackUrl' && !is_array($value)) {
    try {
      Url::fromUri($value);
    } catch (\Exception $exception) {

      /** @var \Drupal\apigee_edge\Entity\App $app */
      $app = parent::set($field_name, '', $notify);
      $app
        ->setCallbackUrl($value);
      return $app;
    }
  }
  return parent::set($field_name, $value, $notify);
}