canCreatePlaceholder example

if ($cached_placeholder_result !== FALSE) {
        return $cached_placeholder_result;
      }
    }

    $cached_element = parent::get($elements);

    if ($cached_element === FALSE) {
      return FALSE;
    }
    else {
      if ($this->placeholderGenerator->canCreatePlaceholder($elements) && $this->placeholderGenerator->shouldAutomaticallyPlaceholder($cached_element)) {
        return $this->createPlaceholderAndRemember($cached_element$elements);
      }

      return $cached_element;
    }
  }

  /** * {@inheritdoc} */
  public function set(array &$elements, array $pre_bubbling_elements) {
    
'#lazy_builder_preview',
        '#preview',
        // The keys below are not actually supported, but these are added         // automatically by the Renderer. Adding them as though they are         // supported allows us to avoid throwing an exception 100% of the time.         '#weight',
        '#printed',
      ];
      assert(empty(array_diff(array_keys($elements)$supported_keys))sprintf('When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: %s.', implode(', ', array_diff(array_keys($elements)$supported_keys))));
    }
    // Determine whether to do auto-placeholdering.     if ($this->placeholderGenerator->canCreatePlaceholder($elements) && $this->placeholderGenerator->shouldAutomaticallyPlaceholder($elements)) {
      $elements['#create_placeholder'] = TRUE;
    }
    // If instructed to create a placeholder, and a #lazy_builder callback is     // present (without such a callback, it would be impossible to replace the     // placeholder), replace the current element with a placeholder.     // @todo remove the isMethodCacheable() check when     // https://www.drupal.org/node/2367555 lands.     if (isset($elements['#create_placeholder']) && $elements['#create_placeholder'] === TRUE && $this->requestStack->getCurrentRequest()->isMethodCacheable()) {
      if (!isset($elements['#lazy_builder'])) {
        throw new \LogicException('When #create_placeholder is set, a #lazy_builder callback must be present as well.');
      }
      
Home | Imprint | This part of the site doesn't use cookies.