getInlineImages() as $inlineImage) { $label = format_string('@caption by @photographer (@filename: @filesize)', [ '@caption' => $inlineImage['fields']['caption'], '@photographer' => $inlineImage['fields']['photographer'], '@filename' => $inlineImage['fields']['image']['filename'], '@filesize' => format_size($inlineImage['fields']['image']['filesize']), ]); $files[] = [$label, $inlineImage['entity_id']]; } drupal_json_output(array_values($files)); drupal_exit(); } function mkbh_article_ajax_inline_quotes_callback($node) { /** @var NodeAdapterInterface $adapter */ $adapter = new NodeAdapterProxy($node); $quotes = []; $trim_options = [ 'max_length' => 64, 'word_boundary' => TRUE, 'ellipsis' => TRUE, 'html' => TRUE, ]; foreach ($adapter->getInlineQuotes() as $delta => $quote) { $label = views_trim_text($trim_options, $quote); $quotes[] = [$label, $delta]; } drupal_json_output(array_values($quotes)); drupal_exit(); } function mkbh_article_ajax_inline_facts_callback($node) { /** @var NodeAdapterInterface $adapter */ $adapter = new NodeAdapterProxy($node); $facts = []; $trim_options = [ 'max_length' => 64, 'word_boundary' => TRUE, 'ellipsis' => TRUE, 'html' => TRUE, ]; foreach ($adapter->getInlineFacts() as $fact) { $label = format_string('#@id: @teaser', [ '@id' => $fact['entity_id'], '@teaser' => views_trim_text($trim_options, strip_tags($fact['fields']['content'])), ]); $facts[] = [$label, $fact['entity_id']]; } drupal_json_output(array_values($facts)); drupal_exit(); } function mkbh_article_ajax_inline_articles_callback($node) { $articles = []; $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node')->entityCondition('bundle', [ 'article', 'vision', 'you_write', 'projekt', 'review', 'photo_series', ])->propertyCondition('status', NODE_PUBLISHED)->propertyOrderBy('title', 'ASC'); $result = $query->execute(); if (isset($result['node'])) { $nodeIds = array_keys($result['node']); $nodes = entity_load('node', $nodeIds); $bundleMap = [ 'vision' => 'Visioner', 'you_write' => 'Du skriver', 'projekt' => 'Projekter', 'review' => 'Anmeldelser', 'photo_series' => 'Foto', ]; foreach ($nodes as $node) { $nodeWrapper = entity_metadata_wrapper('node', $node); $shouldBeAdded = FALSE; $nodeType = $nodeWrapper->value()->type; if (in_array($nodeType, ['vision', 'you_write', 'projekt', 'review', 'photo_series'])) { $labelArgs = [ '@bundle' => $bundleMap[$nodeType], '@title' => $nodeWrapper->value()->title, ]; if ($nodeType === 'vision') { $shouldBeAdded = TRUE; } } else { if (isset($nodeWrapper->field_article_lang_laeser) && (boolean)$nodeWrapper->field_article_lang_laeser->value() === TRUE) { $shouldBeAdded = TRUE; // add Lang Laeser to the results set. $labelArgs = [ '@bundle' => 'Lang læser', '@title' => $nodeWrapper->value()->title, ]; } else { $articleType = $nodeWrapper->field_article_type->value(); if (in_array($articleType->tid, [5, 6, 8])) { // add Byens Rum & Beyns Liv to the results set. $shouldBeAdded = TRUE; } $labelArgs = [ '@bundle' => $articleType->name, '@title' => $nodeWrapper->value()->title, ]; } } $labelArgs['@title'] = views_trim_text([ 'max_length' => 64, 'word_boundary' => TRUE, 'ellipsis' => TRUE, 'html' => TRUE, ], $labelArgs['@title']); if ($shouldBeAdded === TRUE) { $articles[] = [ t('@bundle - @title', $labelArgs), $nodeWrapper->getIdentifier(), ]; } } } sort($articles); drupal_json_output(array_values($articles)); drupal_exit(); } function mkbh_article_ajax_inline_map_sources_callback($node) { $articles = []; try { $query = database()->getConnection() ->table('node as node') ->join('location_instance as location', function ($join) { $join ->on('node.nid', '=', 'location.nid'); }) ->leftJoin('field_data_field_article_type as field_article_type', function ($join) { $join ->on('node.nid', '=', 'field_article_type.entity_id') ->where('field_article_type.entity_type', '=', 'node'); }) ->leftJoin('field_data_field_article_lang_laeser as field_article_lang_laeser', function ($join) { $join ->on('node.nid', '=', 'field_article_lang_laeser.entity_id') ->where('field_article_lang_laeser.entity_type', '=', 'node'); }) ->leftJoin('taxonomy_term_data as taxonomy', function ($join) { $join ->on('field_article_type.field_article_type_target_id', '=', 'taxonomy.tid'); }) ->select([ 'node.*', 'location.lid as location_lid', 'taxonomy.name as article_type_name', 'field_article_lang_laeser.field_article_lang_laeser_value as field_article_lang_laeser' ]) ->whereIn('type', [ 'article', 'vision', 'you_write', 'projekt', 'review', 'photo_series', ]) ->where('status', NODE_PUBLISHED) ->distinct() ->orderBy('created', 'desc'); $query->get()->each(function ($node) use (&$articles) { if (array_key_exists($node->nid, $articles)) { return true; } $bundleMap = [ 'vision' => 'Visioner', 'you_write' => 'Du skriver', 'projekt' => 'Projekter', 'review' => 'Anmeldelser', 'photo_series' => 'Foto', ]; if (array_key_exists($node->type, $bundleMap)) { $labelArgs = [ '@bundle' => $bundleMap[$node->type], '@title' => $node->title, ]; } elseif (isset($node->field_article_lang_laeser) && (boolean)$node->field_article_lang_laeser === TRUE) { $labelArgs = [ '@bundle' => 'Lang læser', '@title' => $node->title, ]; } else { $labelArgs = [ '@bundle' => $node->article_type_name, '@title' => $node->title, ]; } $labelArgs['@title'] = views_trim_text([ 'max_length' => 64, 'word_boundary' => TRUE, 'ellipsis' => TRUE, 'html' => TRUE, ], $labelArgs['@title']); $articles[$node->nid] = [ t('@bundle - @title', $labelArgs), $node->nid, ]; return true; }); drupal_json_output(array_values($articles)); drupal_exit(); } catch (\Exception $e) { drupal_json_output([ 'status' => 'error', 'message' => $e->getMessage(), ]); drupal_exit(); } } function mkbh_article_ajax_parse_inline_map_token_callback($node, $token = NULL) { module_load_include('inc', 'mkbh_article_page', 'mkbh_article_page.helpers'); $data = []; if (is_null($token)) { drupal_json_output($data); drupal_exit(); } $tokens = _mkbh_article_page_parse_tokens($token); if (!empty($tokens['mkbh_article'])) { $token = reset($tokens['mkbh_article']); list($title, $preface, $source) = $token['arguments']; $data = [ 'title' => $title, 'preface' => $preface, 'source' => $source, ]; } drupal_json_output($data); drupal_exit(); }