You are here

public static function Helper::updatePageJson in Structured Data (JSON+LD Rich Snippets) 8

Update Page JSON.

Parameters

array $entity: Entity.

Throws

\Exception

1 call to Helper::updatePageJson()
PageJsonForm::submitForm in src/Form/PageJsonForm.php
Form submission handler.

File

src/Core/Helper.php, line 131

Class

Helper
Class Helper.

Namespace

Drupal\structured_data\Core

Code

public static function updatePageJson(array &$entity) {
  $existing_obj = self::getPageJson($entity);
  if (empty($entity['entity_id'])) {
    unset($entity['bundle']);
    unset($entity['entity_id']);
  }
  if ($existing_obj == NULL) {
    $entity['id'] = \Drupal::database()
      ->insert('structured_data_json')
      ->fields($entity)
      ->execute();
  }
  else {
    \Drupal::database()
      ->update('structured_data_json')
      ->fields($entity)
      ->condition('id', $existing_obj->id)
      ->execute();
  }
}