当前位置: 首页>>代码示例>>PHP>>正文


PHP Element::child方法代码示例

本文整理汇总了PHP中Drupal\Core\Render\Element::child方法的典型用法代码示例。如果您正苦于以下问题:PHP Element::child方法的具体用法?PHP Element::child怎么用?PHP Element::child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Render\Element的用法示例。


在下文中一共展示了Element::child方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: flattenKeysArray

 /**
  * Extracts the positive keywords from a keys array.
  *
  * @param array $keys
  *   A search keys array, as specified by
  *   \Drupal\search_api\Query\QueryInterface::getKeys().
  *
  * @return string[]
  *   An array of all unique positive keywords contained in the keys array.
  */
 protected function flattenKeysArray(array $keys)
 {
     if (!empty($keys['#negation'])) {
         return array();
     }
     $keywords = array();
     foreach ($keys as $i => $key) {
         if (!Element::child($i)) {
             continue;
         }
         if (is_array($key)) {
             $keywords += $this->flattenKeysArray($key);
         } else {
             $keywords[$key] = $key;
         }
     }
     return $keywords;
 }
开发者ID:curveagency,项目名称:intranet,代码行数:28,代码来源:Highlight.php

示例2: createKeysQuery

  /**
   * Creates a SELECT query for given search keys.
   *
   * Used as a helper method in createDbQuery() and createFilterCondition().
   *
   * @param string|array $keys
   *   The search keys, formatted like the return value of
   *   \Drupal\search_api\Query\QueryInterface::getKeys(), but preprocessed
   *   according to internal requirements.
   * @param array $fields
   *   The fulltext fields on which to search, with their names as keys mapped
   *   to internal information about them.
   * @param array $all_fields
   *   Internal information about all indexed fields on the index.
   * @param \Drupal\search_api\IndexInterface $index
   *   The index we're searching on.
   *
   * @return \Drupal\Core\Database\Query\SelectInterface
   *   A SELECT query returning item_id and score (or only item_id, if
   *   $keys['#negation'] is set).
   */
  protected function createKeysQuery($keys, array $fields, array $all_fields, IndexInterface $index) {
    if (!is_array($keys)) {
      $keys = array(
        '#conjunction' => 'AND',
        $keys,
      );
    }

    $neg = !empty($keys['#negation']);
    $conj = $keys['#conjunction'];
    $words = array();
    $nested = array();
    $negated = array();
    $db_query = NULL;
    $mul_words = FALSE;
    $neg_nested = $neg && $conj == 'AND';

    foreach ($keys as $i => $key) {
      if (!Element::child($i)) {
        continue;
      }
      if (is_scalar($key)) {
        $words[] = $key;
      }
      elseif (empty($key['#negation'])) {
        if ($neg) {
          // If this query is negated, we also only need item IDs from
          // subqueries.
          $key['#negation'] = TRUE;
        }
        $nested[] = $key;
      }
      else {
        $negated[] = $key;
      }
    }
    $subs = count($words) + count($nested);
    $not_nested = ($subs <= 1 && count($fields) == 1) || ($neg && $conj == 'OR' && !$negated);

    if ($words) {
      // All text fields in the index share a table. Get name from the first.
      $field = reset($fields);
      $db_query = $this->database->select($field['table'], 't');
      $mul_words = count($words) > 1;
      if ($neg_nested) {
        $db_query->fields('t', array('item_id', 'word'));
      }
      elseif ($neg) {
        $db_query->fields('t', array('item_id'));
      }
      elseif ($not_nested) {
        $db_query->fields('t', array('item_id', 'score'));
      }
      else {
        $db_query->fields('t', array('item_id', 'score', 'word'));
      }
      $db_query->condition('word', $words, 'IN');
      $db_query->condition('field_name', array_map(array(__CLASS__, 'getTextFieldName'), array_keys($fields)), 'IN');
    }

    if ($nested) {
      $word = '';
      foreach ($nested as $k) {
        $query = $this->createKeysQuery($k, $fields, $all_fields, $index);
        if (!$neg) {
          $word .= ' ';
          $var = ':word' . strlen($word);
          $query->addExpression($var, 'word', array($var => $word));
        }
        if (!isset($db_query)) {
          $db_query = $query;
        }
        elseif ($not_nested) {
          $db_query->union($query, 'UNION');
        }
        else {
          $db_query->union($query, 'UNION ALL');
        }
      }
//.........这里部分代码省略.........
开发者ID:jkyto,项目名称:agolf,代码行数:101,代码来源:Database.php

示例3: testChild

 /**
  * Tests the child() method.
  */
 public function testChild()
 {
     $this->assertFalse(Element::child('#property'));
     $this->assertTrue(Element::child('property'));
     $this->assertTrue(Element::child('property#'));
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:9,代码来源:ElementTest.php

示例4: processKeys

 /**
  * Preprocesses the search keywords.
  *
  * Calls processKey() for individual strings.
  *
  * @param array|string $keys
  *   Either a parsed keys array, or a single keywords string.
  */
 protected function processKeys(&$keys)
 {
     if (is_array($keys)) {
         foreach ($keys as $key => &$v) {
             if (Element::child($key)) {
                 $this->processKeys($v);
                 if ($v === '') {
                     unset($keys[$key]);
                 }
             }
         }
     } else {
         $this->processKey($keys);
     }
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:23,代码来源:FieldsProcessorPluginBase.php

示例5: createKeysQuery

 /**
  * Creates a SELECT query for given search keys.
  *
  * Used as a helper method in createDbQuery() and createDbCondition().
  *
  * @param string|array $keys
  *   The search keys, formatted like the return value of
  *   \Drupal\search_api\Query\QueryInterface::getKeys(), but preprocessed
  *   according to internal requirements.
  * @param array $fields
  *   The fulltext fields on which to search, with their names as keys mapped
  *   to internal information about them.
  * @param array $all_fields
  *   Internal information about all indexed fields on the index.
  * @param \Drupal\search_api\IndexInterface $index
  *   The index we're searching on.
  *
  * @return \Drupal\Core\Database\Query\SelectInterface
  *   A SELECT query returning item_id and score (or only item_id, if
  *   $keys['#negation'] is set).
  */
 protected function createKeysQuery($keys, array $fields, array $all_fields, IndexInterface $index)
 {
     if (!is_array($keys)) {
         $keys = array('#conjunction' => 'AND', $keys);
     }
     $neg = !empty($keys['#negation']);
     $conj = $keys['#conjunction'];
     $words = array();
     $nested = array();
     $negated = array();
     $db_query = NULL;
     $mul_words = FALSE;
     $neg_nested = $neg && $conj == 'AND';
     $match_parts = !empty($this->configuration['partial_matches']);
     $keyword_hits = array();
     foreach ($keys as $i => $key) {
         if (!Element::child($i)) {
             continue;
         }
         if (is_scalar($key)) {
             $words[] = $key;
         } elseif (empty($key['#negation'])) {
             if ($neg) {
                 // If this query is negated, we also only need item IDs from
                 // subqueries.
                 $key['#negation'] = TRUE;
             }
             $nested[] = $key;
         } else {
             $negated[] = $key;
         }
     }
     $word_count = count($words);
     $subs = $word_count + count($nested);
     $not_nested = $subs <= 1 && count($fields) == 1 || $neg && $conj == 'OR' && !$negated;
     if ($words) {
         // All text fields in the index share a table. Get name from the first.
         $field = reset($fields);
         $db_query = $this->database->select($field['table'], 't');
         $mul_words = $word_count > 1;
         if ($neg_nested) {
             $db_query->fields('t', array('item_id', 'word'));
         } elseif ($neg) {
             $db_query->fields('t', array('item_id'));
         } elseif ($not_nested) {
             $db_query->fields('t', array('item_id', 'score'));
         } else {
             $db_query->fields('t', array('item_id', 'score', 'word'));
         }
         if (!$match_parts) {
             $db_query->condition('word', $words, 'IN');
         } else {
             $db_or = new Condition('OR');
             // GROUP BY all existing non-grouped, non-aggregated columns – except
             // "word", which we remove since it will be useless to us in this case.
             $columns =& $db_query->getFields();
             unset($columns['word']);
             foreach (array_keys($columns) as $column) {
                 $db_query->groupBy($column);
             }
             foreach ($words as $i => $word) {
                 $db_or->condition('t.word', '%' . $this->database->escapeLike($word) . '%', 'LIKE');
                 // Add an expression for each keyword that shows whether the indexed
                 // word matches that particular keyword. That way we don't return a
                 // result multiple times if a single indexed word (partially) matches
                 // multiple keywords. We also remember the column name so we can
                 // afterwards verify that each word matched at least once.
                 $alias = 'w' . $i;
                 $alias = $db_query->addExpression("t.word LIKE '%" . $this->database->escapeLike($word) . "%'", $alias);
                 $db_query->groupBy($alias);
                 $keyword_hits[] = $alias;
             }
             // Also add expressions for any nested queries.
             for ($i = $word_count; $i < $subs; ++$i) {
                 $alias = 'w' . $i;
                 $alias = $db_query->addExpression('0', $alias);
                 $db_query->groupBy($alias);
                 $keyword_hits[] = $alias;
             }
//.........这里部分代码省略.........
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:101,代码来源:Database.php


注:本文中的Drupal\Core\Render\Element::child方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。