You are here

function populate_published_field in Modal 8.2

Same name and namespace in other branches
  1. 8.3 modal_page.install \populate_published_field()
  2. 5.0.x modal_page.install \populate_published_field()
  3. 4.0.x modal_page.install \populate_published_field()
  4. 4.1.x modal_page.install \populate_published_field()

Set field published.

1 call to populate_published_field()
modal_page_update_8202 in ./modal_page.install
Implements hook_update_N().

File

./modal_page.install, line 194
Install, update and uninstall functions for the Modal Page.

Code

function populate_published_field() {
  $modals = \Drupal::entityTypeManager()
    ->getStorage('modal_page_modal')
    ->loadMultiple();
  foreach ($modals as $modal) {
    $modal->published
      ->setValue(TRUE);
    if ($modal->type->value == 'page' && empty(trim($modal->pages->value))) {
      $modal->published
        ->setValue(FALSE);
    }
    if ($modal->type->value == 'parameter' && empty(trim($modal->paramenters->value))) {
      $modal->published
        ->setValue(FALSE);
    }
    $modal
      ->save();
  }
}