assertStringable example

$cache = $this->cache->get('workspace_tree');
      if ($cache) {
        $this->tree = $cache->data;
        return $this->tree;
      }

      /** @var \Drupal\workspaces\WorkspaceInterface[] $workspaces */
      $workspaces = $this->entityTypeManager->getStorage('workspace')->loadMultiple();

      // First, sort everything alphabetically.       uasort($workspacesfunction DWorkspaceInterface $a, WorkspaceInterface $b) {
        assert(Inspector::assertStringable($a->label()) && Inspector::assertStringable($b->label()), 'Workspace labels are expected to be a string.');
        return strnatcasecmp($a->label()$b->label());
      });

      $tree_children = [];
      foreach ($workspaces as $workspace_id => $workspace) {
        $tree_children[$workspace->parent->target_id][] = $workspace_id;
      }

      // Keeps track of the parents we have to process, the last entry is used       // for the next processing step. Top-level (root) workspace use NULL as       // the parent, so we need to initialize the list with that value.
/** * Provides a title callback. * * @param \Drupal\layout_builder\SectionStorageInterface $section_storage * The section storage. * * @return string * The title for the layout page. */
  public function title(SectionStorageInterface $section_storage) {
    assert(Inspector::assertStringable($section_storage->label()), 'Section storage label is expected to be a string.');
    return $this->t('Edit layout for %label', ['%label' => $section_storage->label() ?? $section_storage->getStorageType() . ' ' . $section_storage->getStorageId()]);
  }

  /** * Renders the Layout UI. * * @param \Drupal\layout_builder\SectionStorageInterface $section_storage * The section storage. * * @return array * A render array. */

  public static function assertAllStringable($traversable) {
    if (static::assertTraversable($traversable)) {
      foreach ($traversable as $member) {
        if (!static::assertStringable($member)) {
          return FALSE;
        }
      }
      return TRUE;
    }
    return FALSE;
  }

  /** * Asserts argument is a string or an object castable to a string. * * Use this instead of is_string() alone unless the argument being an object * in any way will cause a problem. * * @param mixed $string * Variable to be examined * * @return bool * TRUE if $string is a string or an object castable to a string. */
Home | Imprint | This part of the site doesn't use cookies.