You are here

public function BookAccessHelper::updateDefaultsSettings in Book access 1.x

Update defaults from book_admin_settings form.

Parameters

array $book_access_defaults: The book_access_defaults value.

Return value

bool Whether the update succeeded or not.

File

src/BookAccessHelper.php, line 208

Class

BookAccessHelper
Helper functions for book_access.

Namespace

Drupal\book_access

Code

public function updateDefaultsSettings(array $book_access_defaults) : bool {
  $result = TRUE;
  foreach ($book_access_defaults as $id => $book_access_default) {
    $grant_values = [];
    foreach ($book_access_default as $key => $item) {
      $grant_values[$key] = boolval($item);
    }
    try {

      /** @var \Drupal\book_access\Entity\BookAccessDefaultsInterface $accessDefault */
      $accessDefault = $this->entityTypeManager
        ->getStorage('book_access_defaults')
        ->load($id);
      $accessDefault
        ->set('grants', $grant_values)
        ->save();
    } catch (EntityStorageException|InvalidPluginDefinitionException|PluginNotFoundException $e) {
      $result = FALSE;
      break;
    }
  }
  return $result;
}