You are here

public function SolrFieldTypeListBuilder::getSchemaExtraFieldsXml in Search API Solr 8.3

Same name and namespace in other branches
  1. 8.2 src/Controller/SolrFieldTypeListBuilder.php \Drupal\search_api_solr\Controller\SolrFieldTypeListBuilder::getSchemaExtraFieldsXml()
  2. 4.x src/Controller/SolrFieldTypeListBuilder.php \Drupal\search_api_solr\Controller\SolrFieldTypeListBuilder::getSchemaExtraFieldsXml()

Returns the formatted XML for solrconfig_extra.xml.

Parameters

int|null $solr_major_version:

Throws

\Drupal\search_api\SearchApiException

File

src/Controller/SolrFieldTypeListBuilder.php, line 256

Class

SolrFieldTypeListBuilder
Provides a listing of SolrFieldType.

Namespace

Drupal\search_api_solr\Controller

Code

public function getSchemaExtraFieldsXml(?int $solr_major_version = NULL) {
  $xml = '';

  /* @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */
  foreach ($this
    ->getEnabledEntities() as $solr_field_type) {
    foreach ($solr_field_type
      ->getStaticFields() as $static_field) {
      $xml .= '<field ';
      foreach ($static_field as $attribute => $value) {

        /* @noinspection NestedTernaryOperatorInspection */
        $xml .= $attribute . '="' . (is_bool($value) ? $value ? 'true' : 'false' : $value) . '" ';
      }
      $xml .= "/>\n";
    }
    foreach ($solr_field_type
      ->getDynamicFields($solr_major_version) as $dynamic_field) {
      $xml .= '<dynamicField ';
      foreach ($dynamic_field as $attribute => $value) {

        /* @noinspection NestedTernaryOperatorInspection */
        $xml .= $attribute . '="' . (is_bool($value) ? $value ? 'true' : 'false' : $value) . '" ';
      }
      $xml .= "/>\n";
    }
    foreach ($solr_field_type
      ->getCopyFields() as $copy_field) {
      $xml .= '<copyField ';
      foreach ($copy_field as $attribute => $value) {

        /* @noinspection NestedTernaryOperatorInspection */
        $xml .= $attribute . '="' . (is_bool($value) ? $value ? 'true' : 'false' : $value) . '" ';
      }
      $xml .= "/>\n";
    }
  }
  return $xml;
}