You are here

public function WebformCardsManager::getNumberOfCards in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_cards/src/WebformCardsManager.php \Drupal\webform_cards\WebformCardsManager::getNumberOfCards()

Counts the number of cards used in a webform.

Parameters

\Drupal\webform\WebformInterface $webform: A webform.

Return value

int The number of cards for the webform.

Overrides WebformCardsManagerInterface::getNumberOfCards

1 call to WebformCardsManager::getNumberOfCards()
WebformCardsManager::hasCards in modules/webform_cards/src/WebformCardsManager.php
Determine if a webform has cards.

File

modules/webform_cards/src/WebformCardsManager.php, line 53

Class

WebformCardsManager
Manage webform cards.

Namespace

Drupal\webform_cards

Code

public function getNumberOfCards(WebformInterface $webform) {
  $elements = $webform
    ->getElementsDecoded();
  $count = 0;
  foreach ($elements as $element) {
    if (is_array($element)) {
      $element_plugin = $this->elementManager
        ->getElementInstance($element);
      if ($element_plugin instanceof WebformCard) {
        $count++;
      }
    }
  }
  return $count;
}