You are here

static function SearchApiEtHelper::splitItemId in Search API Entity Translation 7.2

Helper function to split the Item ID into language or entity_id.

Parameters

$item_id: The Item ID (in the form "{entity_id}/{language}")

string $return_part: The item part to return, available options: 'entity_id' or 'language'

Return value

array|string|null Returns <entity_id, language> couple, if no $part is given. Returns an empty array if the item_id is not valid.

5 calls to SearchApiEtHelper::splitItemId()
SearchApiEtDatasourceController::getMetadataWrapper in includes/SearchApiEtDatasourceController.php
Creates a metadata wrapper for this datasource controller's type.
SearchApiEtDatasourceController::loadItems in includes/SearchApiEtDatasourceController.php
Loads items of the type of this data source controller.
SearchApiEtHelper::getGroupedItemsIdsByEntity in includes/SearchApiEtHelper.php
Helper function to group the given list of ItemIds by EntityIds
SearchApiEtHelperTest::testSplitItemId in tests/SearchApiEtHelperTest.php
@dataProvider dataProviderSplitItemId
SearchApiEtViewsQuery::addResults in includes/SearchApiEtViewsQuery.php
Helper function for adding results to a view in the format expected by the view.

File

includes/SearchApiEtHelper.php, line 56
Helper class for SearchAPI ET

Class

SearchApiEtHelper
@file Helper class for SearchAPI ET

Code

static function splitItemId($item_id, $return_part = NULL) {
  if (!self::isValidItemId($item_id)) {
    return array();
  }
  $parts_names = array(
    self::ITEM_ID_ENTITY_ID,
    self::ITEM_ID_LANGUAGE,
  );

  // Split the item_id in its parts: {entity_id}/{language}
  $item_id_components = explode(self::ITEM_ID_SEPARATOR, $item_id);
  $item_id_components = array_combine($parts_names, $item_id_components);
  if (!empty($return_part)) {
    if (array_key_exists($return_part, $item_id_components)) {
      return $item_id_components[$return_part];
    }
    else {
      return NULL;
    }
  }
  return $item_id_components;
}