You are here

public function PardotScoreFormBase::exists in Pardot Integration 8

Checks for an existing Pardot Score.

Parameters

string|int $entity_id: The entity ID.

array $element: The form element.

FormStateInterface $form_state: The form state.

Return value

bool TRUE if this Pardot Score already exists, FALSE otherwise.

File

src/Form/PardotScoreFormBase.php, line 127

Class

PardotScoreFormBase
Class PardotScoreFormBase.

Namespace

Drupal\pardot\Form

Code

public function exists($entity_id, array $element, FormStateInterface $form_state) {

  // Use the query factory to build a new Pardot Score entity query.
  $query = $this->query_factory
    ->get('pardot_score');

  // Query the entity ID to see if its in use.
  $result = $query
    ->condition('id', $element['#field_prefix'] . $entity_id)
    ->execute();

  // We don't need to return the ID, only if it exists or not.
  return (bool) $result;
}