<?php

/**
 * Implements hook_init().
 */
function mkbh_blocks_init()
{
    module_load_include('inc', 'mkbh_blocks', 'mkbh_blocks.helpers');
    module_load_include('inc', 'mkbh_blocks', 'mkbh_blocks.theme');
}

/**
 * Implements hook_ctools_plugin_directory().
 *
 * @param $owner
 * @param $plugin_type
 *
 * @return string
 */
function mkbh_blocks_ctools_plugin_directory($owner, $plugin_type)
{
    if ($owner == 'ctools' && in_array($plugin_type, ['content_types'])) {
        return 'includes/plugins/' . $plugin_type;
    }
}

/**
 * Implements hook_block_info().
 *
 * @return array
 */
function mkbh_blocks_block_info()
{
    return [
        'mkbh_block_front_byens_rum' => [
            'info' => t('[Front Page] "Byens rum & Byens liv" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_bliv_static' => [
            'info' => t('[Front Page] "Bliv KBH’er" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_front_byens_rum_small' => [
            'info' => t('[Front Page] "Byens rum & Byens liv" Small Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_front_land_laeser' => [
            'info' => t('[Front Page] "Land Laeser" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_front_du_skriver' => [
            'info' => t('[Front Page] "Du Skriver" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_front_popular' => [
            'info' => t('[Front Page] "Popular" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_front_film' => [
            'info' => t('[Front Page] "Film" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_front_scene' => [
            'info' => t('[Front Page] "Scene" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_front_visioner' => [
            'info' => t('[Front Page] "Visioner" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],

        'mkbh_block_article_header' => [
            'info' => t('[Article] "Header" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_article_main_photo' => [
            'info' => t('[Article] "Main Photo" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_article_related' => [
            'info' => t('[Article] "Related content" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_article_visioner' => [
            'info' => t('[Article] "Related visioner" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_article_lang_lesser' => [
            'info' => t('[Article] "Lang Lesser" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_article_sponsoreret' => [
            'info' => t('[Article] "Seneste Sponsoreret" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],

        'mkbh_block_byens_liv_seneste' => [
            'info' => t('[Byens liv] "senesete" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_byens_rum_seneste' => [
            'info' => t('[Byens rum] "senesete" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_byens_liv_laeser' => [
            'info' => t('[Byens liv] "lang læser" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_byens_rum_laeser' => [
            'info' => t('[Byens rum] "lang læser" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_byens_liv_popular' => [
            'info' => t('[Byens liv] "Popular" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_byens_rum_popular' => [
            'info' => t('[Byens rum] "Popular" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_opinion_seneste' => [
            'info' => t('[Opinion] "seneste" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_opinion_popular' => [
            'info' => t('[Opinion] "Popular" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_projekter_popular' => [
            'info' => t('[Projekter] "Popular" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_support_bar' => [
            'info' => t('[Global] "Support bar" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_new_sponsor_bar' => [
            'info' => t('[Article] "New sponsor bar" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_article_support_block' => [
            'info' => t('[Article] "In Article Support" Block'),
            'cache' => DRUPAL_CACHE_GLOBAL,
        ],
        'mkbh_block_node_tag_buttons' => [
              'info' => t('Tag Buttons for  Content Type'),
              'cache' => DRUPAL_CACHE_GLOBAL,
          ],
        'mkbh_block_vocabulary_header' => [
          'info' => t('Vocabulary Header'),
          'cache' => DRUPAL_CACHE_GLOBAL,
          'region' => 'content',
          'status' => 1,
          'weight' => -10,
          'visibility' => BLOCK_VISIBILITY_PHP,
          'pages' => '<?php return (bool) menu_get_object("taxonomy_term", 2) ?>'
        ],
    ];
}

/**
 * Implements hook_block_configure
 *
 * @param string $delta
 *
 * @return array
 */
function mkbh_blocks_block_configure($delta = '')
{
    $form = [];

    switch ($delta) {
        case 'mkbh_block_bliv_static':
            $fields = [
                'mkbh_block_bliv_static_column_1' => 'Column 1',
                'mkbh_block_bliv_static_column_2' => 'Column 2',
                'mkbh_block_bliv_static_column_3' => 'Column 3',
                'mkbh_block_bliv_static_column_4' => 'Column 4',
            ];

            $default_settings = variable_get('mkbh_block_bliv_static_settings', []);

            foreach ($fields as $field => $label) {
                $form[$field] = [
                    '#type' => 'text_format',
                    '#title' => $label,
                    '#default_value' => (empty($default_settings[$field]['value']) ? '' : $default_settings[$field]['value']),
                    '#format' => (empty($default_settings[$field]['format']) ? 'full_html' : $default_settings[$field]['format']),
                ];
            }

            break;

        case 'mkbh_block_front_du_skriver':
            $default_settings = variable_get('mkbh_block_front_du_skriver_settings', []);
            $form['block_title'] = [
                '#type' => 'textfield',
                '#title' => t('Title'),
                '#default_value' => (empty($default_settings['block_title']) ? '' : $default_settings['block_title']),
            ];
            $form['block_body'] = [
                '#type' => 'text_format',
                '#title' => t('Description'),
                '#default_value' => (empty($default_settings['block_body']['value']) ? '' : $default_settings['block_body']['value']),
                '#format' => (empty($default_settings['block_body']['format']) ? 'full_html' : $default_settings['block_body']['format']),
            ];
            $form['link_text'] = [
                '#type' => 'textfield',
                '#title' => t('Link: Title'),
                '#default_value' => (empty($default_settings['link_text']) ? '' : $default_settings['link_text']),
            ];
            $form['link_href'] = [
                '#type' => 'textfield',
                '#title' => t('Link: href'),
                '#default_value' => (empty($default_settings['link_href']) ? '' : $default_settings['link_href']),
            ];
            break;

        case 'mkbh_block_front_popular':
            $options = _mkbh_blocks_get_all_views_options();
            $default_settings = variable_get('mkbh_block_front_popular_settings', []);

            $form['columns'] = [
                '#type' => 'fieldset',
                '#title' => t('Content settings'),
            ];

            $form['columns']['mkbh_popular_column_1'] = [
                '#title' => t("Column 1"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_1']) ? '' : $default_settings['mkbh_popular_column_1']),
            ];
            $form['columns']['mkbh_popular_column_2'] = [
                '#title' => t("Column 2"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_2']) ? '' : $default_settings['mkbh_popular_column_2']),
            ];
            $form['columns']['mkbh_popular_column_3'] = [
                '#title' => t("Column 3"),
                '#type' => 'textarea',
                '#default_value' => (empty($default_settings['mkbh_popular_column_3']) ? '' : $default_settings['mkbh_popular_column_3']),
            ];
            break;

        case 'mkbh_block_front_film':
            $options = _mkbh_blocks_get_all_views_options();
            $default_settings = variable_get('mkbh_block_front_film_settings', []);

            $form['columns'] = [
                '#type' => 'fieldset',
                '#title' => t('Content settings'),
            ];

            $form['columns']['mkbh_block_front_film_column_content'] = [
                '#title' => t('Content column'),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_block_front_film_column_content']) ? '' : $default_settings['mkbh_block_front_film_column_content']),
            ];

            $form['columns']['mkbh_block_front_film_column_ad'] = [
                '#title' => t("Ad column"),
                '#type' => 'textarea',
                '#default_value' => (empty($default_settings['mkbh_block_front_film_column_ad']) ? '' : $default_settings['mkbh_block_front_film_column_ad']),
            ];

            break;

        case 'mkbh_block_front_scene':
            $options = _mkbh_blocks_get_all_views_options();
            $default_settings = variable_get('mkbh_block_front_scene_settings', []);

            $form['columns'] = [
                '#type' => 'fieldset',
                '#title' => t('Content settings'),
            ];

            $form['columns']['mkbh_block_front_scene_column_content'] = [
                '#title' => t('Content column'),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_block_front_scene_column_content']) ? '' : $default_settings['mkbh_block_front_scene_column_content']),
            ];

            $form['columns']['mkbh_block_front_scene_column_ad'] = [
                '#title' => t("Ad column"),
                '#type' => 'textarea',
                '#default_value' => (empty($default_settings['mkbh_block_front_scene_column_ad']) ? '' : $default_settings['mkbh_block_front_scene_column_ad']),
            ];

            break;

        case 'mkbh_block_front_visioner':
            $default_settings = variable_get('mkbh_block_front_visioner_settings', []);
            $form['block_title'] = [
                '#type' => 'textfield',
                '#title' => t('Title'),
                '#default_value' => (empty($default_settings['block_title']) ? '' : $default_settings['block_title']),
            ];
            $form['block_body'] = [
                '#type' => 'text_format',
                '#title' => t('Description'),
                '#default_value' => (empty($default_settings['block_body']['value']) ? '' : $default_settings['block_body']['value']),
                '#format' => (empty($default_settings['block_body']['format']) ? 'full_html' : $default_settings['block_body']['format']),
            ];
            $form['link_text'] = [
                '#type' => 'textfield',
                '#title' => t('Link: Title'),
                '#default_value' => (empty($default_settings['link_text']) ? '' : $default_settings['link_text']),
            ];
            $form['link_href'] = [
                '#type' => 'textfield',
                '#title' => t('Link: href'),
                '#default_value' => (empty($default_settings['link_href']) ? '' : $default_settings['link_href']),
            ];
            break;

        case 'mkbh_block_opinion_popular':
            $options = _mkbh_blocks_get_all_views_options();
            $default_settings = variable_get('mkbh_block_opinion_popular_settings', []);

            $form['columns'] = [
                '#type' => 'fieldset',
                '#title' => t('Content settings'),
            ];

            $form['columns']['mkbh_popular_column_1'] = [
                '#title' => t("Column 1"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_1']) ? '' : $default_settings['mkbh_popular_column_1']),
            ];
            $form['columns']['mkbh_popular_column_2'] = [
                '#title' => t("Column 2"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_2']) ? '' : $default_settings['mkbh_popular_column_2']),
            ];
            $form['columns']['mkbh_popular_column_3'] = [
                '#title' => t("Ad column"),
                '#type' => 'text_format',
                '#rows' => 10,
                '#format' => (empty($default_settings['mkbh_popular_column_3']['format']) ? 'php_code' : $default_settings['mkbh_popular_column_3']['format']),
                '#default_value' => (empty($default_settings['mkbh_popular_column_3']['value']) ? '' : $default_settings['mkbh_popular_column_3']['value']),
            ];

            break;
        case 'mkbh_block_byens_liv_popular':
            $options = _mkbh_blocks_get_all_views_options();
            $default_settings = variable_get('mkbh_block_byens_liv_popular_settings', []);

            $form['columns'] = [
                '#type' => 'fieldset',
                '#title' => t('Content settings'),
            ];

            $form['columns']['mkbh_popular_column_1'] = [
                '#title' => t("Column 1"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_1']) ? '' : $default_settings['mkbh_popular_column_1']),
            ];
            $form['columns']['mkbh_popular_column_2'] = [
                '#title' => t("Column 2"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_2']) ? '' : $default_settings['mkbh_popular_column_2']),
            ];
            $form['columns']['mkbh_popular_column_3'] = [
                '#title' => t("Ad column"),
                '#type' => 'text_format',
                '#rows' => 10,
                '#format' => (empty($default_settings['mkbh_popular_column_3']['format']) ? 'php_code' : $default_settings['mkbh_popular_column_3']['format']),
                '#default_value' => (empty($default_settings['mkbh_popular_column_3']['value']) ? '' : $default_settings['mkbh_popular_column_3']['value']),
            ];
            break;
        case 'mkbh_block_byens_rum_popular':
            $options = _mkbh_blocks_get_all_views_options();
            $default_settings = variable_get('mkbh_block_byens_rum_popular_settings', []);

            $form['columns'] = [
                '#type' => 'fieldset',
                '#title' => t('Content settings'),
            ];

            $form['columns']['mkbh_popular_column_1'] = [
                '#title' => t("Column 1"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_1']) ? '' : $default_settings['mkbh_popular_column_1']),
            ];
            $form['columns']['mkbh_popular_column_2'] = [
                '#title' => t("Column 2"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_2']) ? '' : $default_settings['mkbh_popular_column_2']),
            ];
            $form['columns']['mkbh_popular_column_3'] = [
                '#title' => t("Ad column"),
                '#type' => 'text_format',
                '#rows' => 10,
                '#format' => (empty($default_settings['mkbh_popular_column_3']['format']) ? 'php_code' : $default_settings['mkbh_popular_column_3']['format']),
                '#default_value' => (empty($default_settings['mkbh_popular_column_3']['value']) ? '' : $default_settings['mkbh_popular_column_3']['value']),
            ];
            break;
        case 'mkbh_block_projekter_popular':
            $options = _mkbh_blocks_get_all_views_options();
            $default_settings = variable_get('mkbh_block_projekter_popular_settings', []);

            $form['columns'] = [
                '#type' => 'fieldset',
                '#title' => t('Content settings'),
            ];

            $form['columns']['mkbh_popular_column_1'] = [
                '#title' => t("Column 1"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_1']) ? '' : $default_settings['mkbh_popular_column_1']),
            ];
            $form['columns']['mkbh_popular_column_2'] = [
                '#title' => t("Column 2"),
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => (empty($default_settings['mkbh_popular_column_2']) ? '' : $default_settings['mkbh_popular_column_2']),
            ];
            $form['columns']['mkbh_popular_column_3'] = [
                '#title' => t("Ad column"),
                '#type' => 'text_format',
                '#rows' => 10,
                '#format' => (empty($default_settings['mkbh_popular_column_3']['format']) ? 'php_code' : $default_settings['mkbh_popular_column_3']['format']),
                '#default_value' => (empty($default_settings['mkbh_popular_column_3']['value']) ? '' : $default_settings['mkbh_popular_column_3']['value']),
            ];
            break;

        case 'mkbh_block_support_bar':
            $form['support_bar_settings_title'] = [
                '#type' => 'item',
                '#title' => t('Block settings'),
            ];

            $form['support_bar_settings'] = [
                '#type' => 'vertical_tabs',
            ];

            $form['support_bar_settings']['colors'] = [
                '#type' => 'fieldset',
                '#title' => t('Styling'),
                '#collapsible' => FALSE,
            ];

            $form['support_bar_settings']['colors']['mkbh_block_support_bar_color_text'] = [
                '#type' => 'textfield',
                '#title' => t('Text color'),
                '#description' => t('Please provide correct color in HEX format, i.e. #ebebeb'),
                '#default_value' => variable_get('mkbh_block_support_bar_color_text', '#ebebeb'),
            ];

            $form['support_bar_settings']['colors']['mkbh_block_support_bar_color_background'] = [
                '#type' => 'textfield',
                '#title' => t('Background color'),
                '#description' => t('Please provide correct color in HEX format, i.e. #c1041f'),
                '#default_value' => variable_get('mkbh_block_support_bar_color_background', '#c1041f'),
            ];

            $form['support_bar_settings']['copyright'] = [
                '#type' => 'fieldset',
                '#title' => t('Copyright'),
                '#collapsible' => FALSE,
            ];

            $form['support_bar_settings']['copyright']['mkbh_block_support_bar_status'] = [
                '#type' => 'select',
                '#title' => t('Bar status'),
                '#options' => [
                    TRUE => t('Enabled'),
                    FALSE => t('Disabled'),
                ],
                '#description' => t('Whatever show support bar or not.'),
                '#default_value' => variable_get('mkbh_block_support_bar_status', TRUE),
            ];

            $form['support_bar_settings']['copyright']['mkbh_block_support_bar_title'] = [
                '#type' => 'textfield',
                '#title' => t('Title'),
                '#description' => t('First line of support bar copyright, displayed in bold.'),
                '#default_value' => variable_get('mkbh_block_support_bar_title', 'København har brug for et uafhængigt medie der vedholdende skaber debat om byens udformning'),
            ];

            $form['support_bar_settings']['copyright']['mkbh_block_support_bar_sub_title'] = [
                '#type' => 'textfield',
                '#title' => t('Sub-title'),
                '#description' => t('Second line of support bar copyright, displayed in normal font weight.'),
                '#default_value' => variable_get('mkbh_block_support_bar_sub_title', 'Men Magasinet KBH kan kun udkomme med støtte fra læserne — bliv medlem fra kun 20 kroner om måneden'),
            ];

            $form['support_bar_settings']['copyright']['mkbh_block_support_bar_clear_cookie'] = [
                '#type' => 'submit',
                '#value' => 'Clear support bar cookie',
                '#attributes' => [
                    'onclick' => "javascript: Cookies.remove('mkbh_block_support_bar_closed'); alert('Cookie cleared!'); return false;",
                ],
                '#attached' => [
                    'js' => [
                        'https://gitcdn.xyz/repo/js-cookie/js-cookie/master/src/js.cookie.js',
                    ],
                ],
            ];

            break;

        case 'mkbh_block_new_sponsor_bar':
            $default_settings = variable_get('mkbh_block_new_sponsor_bar_settings', []);

            $form['columns'] = [
                '#type' => 'fieldset',
                '#title' => t('Content settings'),
            ];

            $form['columns']['active'] = [
                '#title' => t("Active"),
                '#type' => 'checkbox',
                '#default_value' => (isset($default_settings['active']) ? $default_settings['active'] : true),
            ];
            $form['columns']['main_sponsors'] = [
                '#title' => t("Main sponsors"),
                '#type' => 'textarea',
                '#default_value' => (empty($default_settings['main_sponsors']) ? '' : $default_settings['main_sponsors']),
                '#description' => t('Format: title:link')
            ];
            $form['columns']['sponsors'] = [
                '#title' => t("sponsors"),
                '#type' => 'textarea',
                '#default_value' => (empty($default_settings['sponsors']) ? '' : $default_settings['sponsors']),
                '#description' => t('Format: title:link')
            ];
            break;
    }

    return $form;
}

/**
 * Implements hook_form_alter().
 */
function mkbh_blocks_form_block_admin_configure_alter(&$form, &$form_state)
{
    switch ($form['delta']['#value']) {
        case 'mkbh_block_support_bar':
            $form['settings']['support_bar_settings']['block_settings'] = [
                '#type' => 'fieldset',
                '#title' => t('Block settings'),
                '#collapsible' => FALSE,
                '#weight' => 100,
            ];

            $form['settings']['support_bar_settings']['block_regions'] = [
                '#type' => 'fieldset',
                '#title' => t('Block regions'),
                '#collapsible' => FALSE,
                '#weight' => 101,
            ];

            $form['settings']['support_bar_settings']['block_settings']['title'] = $form['settings']['title'];
            unset($form['settings']['title']);

            $form['settings']['support_bar_settings']['block_settings']['css_class'] = $form['settings']['css_class'];
            unset($form['settings']['css_class']);

            $form['settings']['support_bar_settings']['block_regions']['regions'] = $form['regions'];
            unset($form['regions']);

            break;

        case 'mkbh_block_article_support_block':
            $default_settings = variable_get('mkbh_block_article_support_block_settings', []);

            $form['settings']['title']['#access'] = false;
            $form['settings']['css_class']['#access'] = false;
            $form['regions']['#access'] = false;
            $form['visibility_title']['#access'] = false;
            $form['visibility']['#access'] = false;

            $form['content'] = [
                '#type' => 'fieldset',
                '#title' => t('Content settings'),
                "#description" => "Configure content and appearance of the block.",
                "#collapsible" => false,
                '#weight' => 0,

            ];

            $form['content']['content_heading'] = [
                '#title' => t("Heading"),
                '#type' => 'text_format',
                '#format' => 'full_html',
                '#pre_render' => array('ckeditor_pre_render_text_format'),
                '#default_value' => ($default_settings['content_heading'] ?? null),
            ];

            $form['content']['content_body'] = [
                '#title' => t("Body"),
                '#type' => 'text_format',
                '#format' => 'full_html',
                '#pre_render' => array('ckeditor_pre_render_text_format'),
                '#default_value' => ($default_settings['content_body'] ?? null),
            ];

            $form['content']['content_subscript'] = [
                '#title' => t("Subscript"),
                '#type' => 'text_format',
                '#format' => 'full_html',
                '#pre_render' => array('ckeditor_pre_render_text_format'),
                '#default_value' => ($default_settings['content_subscript'] ?? null),
            ];

            if (isset($default_settings['content_image']) && $image = file_load($default_settings['content_image'])) {
                $form['content']['content_image_preview'] = [
                    '#theme' => 'image',
                    '#path' => $image->uri,
                    '#attributes' => [
                        'style' => 'width: 450px;  height: auto;'
                    ]
                ];
            }

            $form['content']['content_image'] = array(
                '#type' => 'managed_file',
                '#name' => 'content_image',
                '#title' => t('Image'),
                '#size' => 40,
                '#upload_location' => 'public://',
                '#default_value' => ($default_settings['content_image'] ?? null),
            );

            $form['content']['content_image_style'] = array(
                '#type' => 'select',
                '#title' => t('Image Style'),
                '#default_value' => ($default_settings['content_image_style'] ?? null),
                '#options' => [
                    'default' => t('Default'),
                    'edge-to-edge' => t('Edge-to-Edge'),
                ]
            );

            $form['content']['content_status'] = [
                '#title' => t("Published?"),
                '#type' => 'checkbox',
                '#default_value' => ($default_settings['content_status'] ?? true),
            ];

            break;
    }
}

/**
 * Implements hook_block_save
 *
 * @param string $delta
 * @param array $edit
 */
function mkbh_blocks_block_save($delta = '', $edit = [])
{
    switch ($delta) {
        case 'mkbh_block_bliv_static':
            $fields = [
                'mkbh_block_bliv_static_column_1',
                'mkbh_block_bliv_static_column_2',
                'mkbh_block_bliv_static_column_3',
                'mkbh_block_bliv_static_column_4',
            ];
            variable_set('mkbh_block_bliv_static_settings', array_intersect_key($edit, array_flip($fields)));

            break;

        case 'mkbh_block_front_du_skriver':
            $fields = ['block_title', 'block_body', 'link_text', 'link_href'];
            variable_set('mkbh_block_front_du_skriver_settings', array_intersect_key($edit, array_flip($fields)));

            break;

        case 'mkbh_block_front_visioner':
            $fields = ['block_title', 'block_body', 'link_text', 'link_href'];
            variable_set('mkbh_block_front_visioner_settings', array_intersect_key($edit, array_flip($fields)));

            break;

        case 'mkbh_block_front_popular':
            $fields = [
                'mkbh_popular_column_1',
                'mkbh_popular_column_2',
                'mkbh_popular_column_3',
            ];
            variable_set('mkbh_block_front_popular_settings', array_intersect_key($edit, array_flip($fields)));

            break;

        case 'mkbh_block_front_film':
            $fields = [
                'mkbh_block_front_film_column_content',
                'mkbh_block_front_film_column_ad',
            ];
            variable_set('mkbh_block_front_film_settings', array_intersect_key($edit, array_flip($fields)));

            break;

        case 'mkbh_block_front_scene':
            $fields = [
                'mkbh_block_front_scene_column_content',
                'mkbh_block_front_scene_column_ad',
            ];
            variable_set('mkbh_block_front_scene_settings', array_intersect_key($edit, array_flip($fields)));

            break;

        case 'mkbh_block_opinion_popular':
            $fields = [
                'mkbh_popular_column_1',
                'mkbh_popular_column_2',
                'mkbh_popular_column_3',
            ];
            variable_set('mkbh_block_opinion_popular_settings', array_intersect_key($edit, array_flip($fields)));

            break;

        case 'mkbh_block_byens_liv_popular':
            $fields = [
                'mkbh_popular_column_1',
                'mkbh_popular_column_2',
                'mkbh_popular_column_3',
            ];
            variable_set('mkbh_block_byens_liv_popular_settings', array_intersect_key($edit, array_flip($fields)));
            break;

        case 'mkbh_block_byens_rum_popular':
            $fields = [
                'mkbh_popular_column_1',
                'mkbh_popular_column_2',
                'mkbh_popular_column_3',
            ];
            variable_set('mkbh_block_byens_rum_popular_settings', array_intersect_key($edit, array_flip($fields)));
            break;

        case 'mkbh_block_projekter_popular':
            $fields = [
                'mkbh_popular_column_1',
                'mkbh_popular_column_2',
                'mkbh_popular_column_3',
            ];
            variable_set('mkbh_block_projekter_popular_settings', array_intersect_key($edit, array_flip($fields)));
            break;

        case 'mkbh_block_support_bar':
            variable_set('mkbh_block_support_bar_color_text', $edit['mkbh_block_support_bar_color_text']);
            variable_set('mkbh_block_support_bar_color_background', $edit['mkbh_block_support_bar_color_background']);
            variable_set('mkbh_block_support_bar_title', $edit['mkbh_block_support_bar_title']);
            variable_set('mkbh_block_support_bar_sub_title', $edit['mkbh_block_support_bar_sub_title']);
            variable_set('mkbh_block_support_bar_status', (boolean)$edit['mkbh_block_support_bar_status']);

            break;

        case 'mkbh_block_new_sponsor_bar':
            $fields = [
                'active',
                'main_sponsors',
                'sponsors',
            ];
            variable_set('mkbh_block_new_sponsor_bar_settings', array_intersect_key($edit, array_flip($fields)));

            break;

        case 'mkbh_block_article_support_block':
            $settings = variable_get('mkbh_block_article_support_block_settings', []);

            $fields = array_intersect_key($edit, array_flip([
                'content_heading',
                'content_body',
                'content_subscript',
                'content_image',
                'content_image_style',
                'content_status',
            ]));

            if (isset($fields['content_image']) && $image = file_load($fields['content_image'])) {
                $image->status = FILE_STATUS_PERMANENT;

                file_save($image);
                file_usage_add($image, 'mkbh_blocks', 'mkbh_block_article_support_block', time());
            }

            $settings['content_heading'] = $fields['content_heading']['value'];
            $settings['content_body'] = $fields['content_body']['value'];
            $settings['content_subscript'] = $fields['content_subscript']['value'];
            $settings['content_image'] = $fields['content_image'];
            $settings['content_image_style'] = $fields['content_image_style'];
            $settings['content_status'] = $fields['content_status'];

            variable_set('mkbh_block_article_support_block_settings', $settings);

            break;

    }
}

/**
 * Implements hook_block_view().
 *
 * @param string $delta
 *
 * @return array
 * @throws Exception
 */
function mkbh_blocks_block_view($delta = '')
{
    global $user;

    $block = [];

    switch ($delta) {
        case 'mkbh_block_front_byens_rum':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_front_byens_rum',
                ],
            ];
            break;

        case 'mkbh_block_bliv_static':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_bliv_static',
                ],
            ];
            break;

        case 'mkbh_block_front_byens_rum_small':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_front_byens_rum_small',
                ],
            ];
            break;

        case 'mkbh_block_front_land_laeser':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_front_land_laeser',
                ],
            ];
            break;

        case 'mkbh_block_front_du_skriver':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_front_du_skriver',
                ],
            ];
            break;

        case 'mkbh_block_front_popular':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_front_popular',
                ],
            ];
            break;

        case 'mkbh_block_front_film':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_front_film',
                ],
            ];
            break;

        case 'mkbh_block_front_scene':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_front_scene',
                ],
            ];
            break;

        case 'mkbh_block_front_visioner':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_front_visioner',
                ],
            ];
            break;

        //Article Details
        case 'mkbh_block_article_header':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_article_header',
                ],
            ];
            break;

        case 'mkbh_block_article_main_photo':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_article_main_photo',
                ],
            ];
            break;

        case 'mkbh_block_article_related':
            $build = [
                '#theme' => 'mkbh_block_article_related',
            ];

            $block = [
                'subject' => NULL,
                'content' => render($build),
            ];
            break;

        case 'mkbh_block_article_visioner':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_article_related_visioner',
                ],
            ];
            break;

        case 'mkbh_block_article_lang_lesser':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_article_lang_lesser',
                ],
            ];
            break;
        case 'mkbh_block_article_sponsoreret':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_article_sponsoreret',
                ],
            ];
            break;

        case 'mkbh_block_byens_liv_seneste':
            drupal_add_library('system', 'drupal.ajax');
            $block = [
                'subject' => NULL,
                'content' => [
                    '#type' => 'container',
                    '#attributes' => [
                        'class' => ['block-wrapper mkbh-block-byens-liv-seneste clearfix'],
                    ],
                    [
                        mkbh_block_byens_rum_liv_seneste_content('liv'),
                    ],
                ],
            ];
            break;

        case 'mkbh_block_byens_rum_seneste':
            drupal_add_library('system', 'drupal.ajax');
            $block = [
                'subject' => NULL,
                'content' => [
                    '#type' => 'container',
                    '#attributes' => [
                        'class' => ['block-wrapper mkbh-block-byens-rum-seneste clearfix'],
                    ],
                    [
                        mkbh_block_byens_rum_liv_seneste_content('rum'),
                    ],
                ],
            ];
            break;

        case 'mkbh_block_byens_liv_laeser':
            $block = [
                'subject' => NULL,
                'content' => mkbh_block_byens_rum_liv_laeser_content('liv'),
            ];
            break;

        case 'mkbh_block_byens_rum_laeser':
            $block = [
                'subject' => NULL,
                'content' => mkbh_block_byens_rum_liv_laeser_content('rum'),
            ];
            break;

        case 'mkbh_block_opinion_seneste':
            drupal_add_library('system', 'drupal.ajax');
            $block = [
                'subject' => NULL,
                'content' => [
                    '#type' => 'container',
                    '#attributes' => [
                        'class' => ['block-wrapper mkbh-block-opinion-seneste clearfix'],
                    ],
                    [
                        mkbh_blocks_get_opinion_seneste_content(),
                    ],
                ],
            ];
            break;

        case 'mkbh_block_opinion_popular':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_opinion_popular',
                ],
            ];
            break;
        case 'mkbh_block_byens_liv_popular';
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_byens_liv_popular',
                ],
            ];
            break;
        case 'mkbh_block_byens_rum_popular':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_byens_rum_popular',
                ],
            ];
            break;
        case 'mkbh_block_projekter_popular':
            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_projekter_popular',
                ],
            ];
            break;

        case 'mkbh_block_support_bar':
            $title = variable_get('mkbh_block_support_bar_title');
            $subTitle = variable_get('mkbh_block_support_bar_sub_title');

            if (variable_get('mkbh_block_support_bar_status', TRUE) === FALSE) {
                break;
            }

            // do not show if title and subtitle left empty
            if (trim($title) === '' && trim($subTitle) === '') {
                break;
            }

            // do not show if user already has stripe subscription
            if (property_exists($user, 'mail') && _mkbh_blocks_user_has_stripe_subscription($user->mail)) {
                break;
            }

            // do not show if user manually closed support bar
            if (isset($_COOKIE['mkbh_block_support_bar_closed']) && TRUE === (boolean)$_COOKIE['mkbh_block_support_bar_closed']) {
                break;
            }

            $blockConfig = block_load('mkbh_blocks', 'mkbh_block_support_bar');
            if ($blockConfig->visibility == BLOCK_VISIBILITY_NOTLISTED) {
                $pages = explode("\n", $blockConfig->pages);

                if (!is_array($pages)) {
                    $pages = [];
                }

                $pages[] = 'node/' . MKBH_DONATE_PERSONAL_NID;

                $currentPath = trim($_GET['q']);

                $pages = array_map(function ($e) {
                    return trim($e);
                }, $pages);

                if (in_array($currentPath, $pages)) {
                    break;
                }
            }

            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_support_bar',
                    '#title' => $title,
                    '#sub_title' => $subTitle,
                    '#color_text' => variable_get('mkbh_block_support_bar_color_text', '#ebebeb'),
                    '#color_background' => variable_get('mkbh_block_support_bar_color_background', '#c1041f'),
                ],
            ];

            break;

        case 'mkbh_block_new_sponsor_bar':
            $settings = variable_get('mkbh_block_new_sponsor_bar_settings', []);

            if (empty($settings) || (array_get($settings, 'active') == FALSE)) {
                break;
            }

            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => 'mkbh_block_new_sponsor_bar'
                ]
            ];

            break;

        case 'mkbh_block_article_support_block':
            $settings = variable_get('mkbh_block_article_support_block_settings', []);

            $break = false;

            if (empty($settings) || (array_get($settings, 'content_status') == FALSE)) {
                $break = true;
            }

            $node = menu_get_object('node');
            $nodeAdapter = entity_metadata_wrapper('node', $node);

            if (isset($user) && property_exists($user, 'mail')) {
                if (_mkbh_blocks_user_has_stripe_subscription($user->mail) && mkbh_paywall_is_user_has_access($node, $user)) {
                    $break = true;
                }
            }

            if (mkbh_paywall_is_user_has_access($node, $user)) {
                $break = true;
            }

            if ($break) {
                break;
            }

            if (!mkbh_paywall_is_user_has_access($node, $user)) {
                if (isset($nodeAdapter->field_article_lang_laeser) && $nodeAdapter->field_article_lang_laeser->value() === TRUE) {
                    $theme = 'mkbh_block_article_support_block_paywall_lang_laeser';
                } else {
                    $theme = 'mkbh_block_article_support_block_paywall_default';
                }
            } else {
                $theme = 'mkbh_block_article_support_block';
            }

            $block = [
                'subject' => NULL,
                'content' => [
                    '#theme' => $theme
                ]
            ];

            break;

      case 'mkbh_block_node_tag_buttons':
        $block = [
          'subject' => t('Emner'),
          'content' => [
            '#theme' => 'mkbh_block_node_tag_buttons',
          ]
        ];
        break;

        case 'mkbh_block_vocabulary_header':
        $block = [
          'subject' => NULL,
          'content' => [
            '#theme' => 'mkbh_block_vocabulary_header',
          ]
        ];
        break;

        default:
            $block = [
                'subject' => NULL,
            ];
    }

    return $block;
}

/**
 * Implements hook_block_view_alter().
 * @throws Exception
 */
function mkbh_blocks_block_view_alter(&$data, $block)
{
    switch ($block->delta) {
        case 'facebook_comments_box':
            $node_type = '';

            // Get which node types should have comments.
            $fcb_node_types = variable_get('facebook_comments_box_default_node_types', [NULL]);

            // Figure out which node and nodetype we're on, puts comments only on
            // nodes (as opposed to the front page, views pages, term pages, etc.)
            if (arg(0) == 'node' && is_numeric(arg(1))) {
                $nid = arg(1);
                $node = node_load($nid);
                $node_type = $node->type;
            }

            // If the nodetype is set and selected in config, then load the comments
            // on the page.
            if (isset($node_type) && in_array($node_type, $fcb_node_types)) {
                // Figure out the current absolute URL.
                $path = isset($_GET['q']) ? $_GET['q'] : '<front>';
                $fcb_url = url($path, ['absolute' => TRUE]);

                $fcb_num_posts = check_plain(variable_get('facebook_comments_box_default_comments', 10));
                $fcb_width = check_plain(variable_get('facebook_comments_box_default_width', 400));
                $fcb_theme = check_plain(variable_get('facebook_comments_box_default_theme', 'light'));

                // Set the title of the block.
                $data['subject'] = t('Facebook Comments Box');

                // Set the content of the block.
                $fcb_content = '<div class="facebook-comments-box">';

                $fcb_content .= theme('mkbh_block_facebook_comments_box_comments_seo', ['url' => $fcb_url]);
                $fcb_content .= '<div class="fb-comments" data-href="' . $fcb_url . '" data-width="' . $fcb_width . '" data-numposts="' . $fcb_num_posts . '" data-colorscheme="' . $fcb_theme . '"></div>';
                $fcb_content .= '</div>';

                $data['content'] = $fcb_content;

                break;
            }
    }
}

/**
 * Implements hook_theme().
 *
 * @return array
 */
function mkbh_blocks_theme()
{
    return [
        'mkbh_block_front_byens_rum' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
        ],
        'mkbh_block_front_byens_rum_left' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_byens_rum/mkbh-block-front-byens-rum-left',
        ],
        'mkbh_block_front_byens_rum_right' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_byens_rum/mkbh-block-front-byens-rum-right',
        ],
        'mkbh_block_front_byens_rum_small' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_byens_rum_small/mkbh-block-front-byens-rum-small',
        ],
        'mkbh_block_front_land_laeser' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_land_laeser/mkbh-block-front-land-laeser',
        ],
        'mkbh_block_bliv_static' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_bliv_static/mkbh-block-bliv-static',
        ],
        'mkbh_block_front_du_skriver' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_du_skriver/mkbh-block-front-du-skriver',
        ],
        'mkbh_block_front_popular' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_popular/mkbh-block-front-popular',
        ],
        'mkbh_block_front_film' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_film/mkbh-block-front-film',
        ],
        'mkbh_block_front_scene' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_scene/mkbh-block-front-scene',
        ],
        'mkbh_block_front_visioner' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_visioner/mkbh-block-front-visioner',
        ],
        'mkbh_block_front_visioner__static_region' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_front_visioner/mkbh-block-front-vision--static-region',
        ],

        'mkbh_article_display__view_mode_large' => [
            'variables' => [
                'node' => NULL,
                'adapter' => NULL,
                'show_body' => NULL,
                'trim_length' => NULL,
                'show_shares_count' => NULL,
                'main_image_view_mode' => NULL,
                'show_color' => FALSE,
                'show_breadcrumbs' => NULL,
                'orientation' => 'vertical',
                'show_writer_name' => FALSE,
                'show_read_more' => FALSE,
                'show_post_date' => FALSE,
                'link_target' => '_self'
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/nodes/article/mkbh-article-display--view-mode-large',
        ],
        'mkbh_article_display__view_mode_medium' => [
            'variables' => [
                'node' => NULL,
                'adapter' => NULL,
                'show_body' => NULL,
                'trim_length' => NULL,
                'show_shares_count' => NULL,
                'main_image_view_mode' => NULL,
                'orientation' => NULL,
                'show_color' => FALSE,
                'show_breadcrumbs' => NULL,
                'show_writer_name' => FALSE,
                'ignore_write_photo' => FALSE,
                'show_read_more' => FALSE,
                'show_post_date' => FALSE,
                'link_target' => '_self'
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/nodes/article/mkbh-article-display--view-mode-medium',
        ],
        'mkbh_article_display__view_mode_small' => [
            'variables' => [
                'node' => NULL,
                'adapter' => NULL,
                'show_body' => NULL,
                'trim_length' => NULL,
                'show_shares_count' => NULL,
                'show_color' => FALSE,
                'show_breadcrumbs' => NULL,
                'show_writer_name' => FALSE,
                'show_read_more' => FALSE,
                'show_post_date' => FALSE,
                'link_target' => '_self'
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/nodes/article/mkbh-article-display--view-mode-small',
        ],
        'mkbh_vision_display__view_mode_large' => [
            'variables' => [
                'node' => NULL,
                'adapter' => NULL,
                'main_image_view_mode' => NULL,
                'show_body' => NULL,
                'trim_length' => 75,
                'show_post_date' => FALSE,
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/nodes/vision/mkbh-vision-display--view-mode-large',
        ],
        'mkbh_vision_display__view_mode_small' => [
            'variables' => [
                'node' => NULL,
                'adapter' => NULL,
                'show_body' => FALSE,
                'show_sub_category' => TRUE,
                'trim_length' => 75,
                'show_post_date' => FALSE,
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/nodes/vision/mkbh-vision-display--view-mode-small',
        ],

        //Article Details
        'mkbh_block_article_header' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_article_header/mkbh-block-article-header',
        ],
        'mkbh_block_article_main_photo' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_article_main_photo/mkbh-block-article-main-photo',
        ],
        'mkbh_block_article_related' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_article_related/mkbh-block-article-related',
        ],
        'mkbh_block_article_related_visioner' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_article_related_visioner/mkbh-block-article-related-visioner',
        ],
        'mkbh_block_article_lang_lesser' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_article_lang_lesser/mkbh-block-article-lang-lesser',
        ],
        'mkbh_block_article_sponsoreret' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_article_sponsoreret/mkbh-block-article-sponsoreret',
        ],

        // Panel Panes
        'mkbh_pane_article_recent_articles' => [
            'variables' => [
                'render_mode' => NULL,
                'bundle' => NULL,
                'sub_types' => [],
                'link' => [],
                'layout' => NULL,
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/panes/mkbh_pane_article_recent_articles/mkbh-pane-article-recent-articles',
        ],
        'mkbh_pane_article_recent_articles__layout_simple_4_columns' => [
            'variables' => [
                'render_mode' => NULL,
                'bundle' => NULL,
                'sub_types' => [],
                'link' => [],
                'layout' => NULL,
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/panes/mkbh_pane_article_recent_articles/mkbh-pane-article-recent-articles--layout-simple-4-columns',
        ],
        'mkbh_pane_views_group' => [
            'variables' => [
                'views_item_1' => NULL,
                'views_item_2' => NULL,
                'views_item_3' => NULL,
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/panes/mkbh_pane_views_group/mkbh-pane-views-group',
        ],
        'mkbh_pane_global_stats' => [
            'variables' => [
                'established' => NULL,
                'page_views' => NULL,
                'fb_fans' => NULL,
                'mc_subscribers' => NULL,
                'ad_description' => NULL,
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/panes/mkbh_pane_global_stats/mkbh-pane-global-stats',
        ],

        // Byens rum/liv pages.
        'mkbh_block_byens_liv_seneste' => [
            'variables' => ['items' => NULL, 'load_more' => NULL],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_byens_liv_seneste/mkbh-block-byens-liv-seneste',
        ],
        'mkbh_block_byens_rum_seneste' => [
            'variables' => ['items' => NULL, 'load_more' => NULL],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_byens_rum_seneste/mkbh-block-byens-rum-seneste',
        ],
        'mkbh_block_byens_liv_laeser' => [
            'variables' => ['items' => NULL],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_byens_liv_laeser/mkbh-block-byens-liv-laeser',
        ],
        'mkbh_block_byens_rum_laeser' => [
            'variables' => ['items' => NULL],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_byens_rum_laeser/mkbh-block-byens-rum-laeser',
        ],
        'mkbh_block_byens_liv_popular' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_byens_liv_popular/mkbh-block-byens-liv-popular',
        ],
        'mkbh_block_byens_rum_popular' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_byens_rum_popular/mkbh-block-byens-rum-popular',
        ],
        'mkbh_block_opinion_seneste' => [
            'variables' => ['items' => NULL, 'load_more' => NULL],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_opinion_seneste/mkbh-block-opinion-seneste',
        ],
        'mkbh_block_opinion_popular' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_opinion_popular/mkbh-block-opinion-popular',
        ],
        'mkbh_block_projekter_popular' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_projekter_popular/mkbh-block-projekter-popular',
        ],
        'mkbh_block_facebook_comments_box_comments_seo' => [
            'variables' => ['url' => NULL],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_facebook_comments_box_comments_seo/mkbh-block-facebook-comments-box-comments-seo',
        ],
        'mkbh_block_support_bar' => [
            'variables' => [
                'title' => NULL,
                'sub_title' => NULL,
                'color_text' => NULL,
                'color_background' => NULL,
            ],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_support_bar/mkbh-block-support-bar',
        ],
        'mkbh_block_new_sponsor_bar' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_new_sponsor_bar/mkbh-block-new-sponsor-bar',
        ],
        'mkbh_block_article_support_block' => [
            'variables' => [],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_article_support_block/mkbh-block-article-support-block',
        ],
        'mkbh_block_article_support_block_paywall_default' => [
            'variables' => ['user_plans' => NULL],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_article_support_block_paywall/mkbh-block-article-support-block-paywall--default',
        ],
        'mkbh_block_article_support_block_paywall_lang_laeser' => [
            'variables' => ['user_plans' => NULL],
            'file' => 'mkbh_blocks.theme.inc',
            'template' => 'templates/blocks/mkbh_block_article_support_block_paywall/mkbh-block-article-support-block-paywall--lang-laeser',
        ],
      'mkbh_block_node_tag_buttons' => [
        'variables' => [
          'options' => [],
          'context' => [],
          'tag_buttons_data' => [],
        ],
        'template' => 'templates/blocks/mkbh_block_node_tag_buttons/mkbh-block-node-tag-buttons',
      ],

      'mkbh_block_vocabulary_header' => [
        'variables' => [
          'options' => [],
          'context' => [],
          'type_text' => NULL,
          'specific_text' => NULL,
          'result_text' => NULL,
          'image' => NULL,
        ],
        'file' => 'mkbh_blocks.theme.inc',
        'template' => 'templates/blocks/mkbh_block_vocabulary_header/mkbh-block-vocabulary-header',
      ],
      'mkbh_block_vocabulary_header__voc_writer_page' => [
        'variables' => [
          'options' => [],
          'context' => [],
          'type_text' => NULL,
          'specific_text' => NULL,
          'result_text' => NULL,
          'image' => NULL,
          'writer_image_url' => NULL,
          'writer_info' => NULL,
        ],
        'file' => 'mkbh_blocks.theme.inc',
        'template' => 'templates/blocks/mkbh_block_vocabulary_header/mkbh-block-vocabulary-header--voc-writer-page',
      ],
    ];
}

/**
 * Implements hook_menu().
 *
 * @see mkbh_block_byens_liv_seneste_load_more()
 * @see mkbh_block_opinion_seneste_load_more()
 */
function mkbh_blocks_menu()
{
    return [
        'byens-rum-liv-seneste-more/%/%' => [
            'title' => 'Ajax load more for byens liv',
            'page callback' => 'mkbh_block_byens_liv_seneste_load_more',
            'page arguments' => [1, 2],
            'delivery callback' => 'ajax_deliver',
            'access callback' => TRUE,
            'type' => MENU_CALLBACK,
        ],
        'opinion-seneste-more/%' => [
            'title' => 'Opinion page load more callback',
            'page callback' => 'mkbh_block_opinion_seneste_load_more',
            'page arguments' => [1],
            'delivery callback' => 'ajax_deliver',
            'access callback' => TRUE,
            'type' => MENU_CALLBACK,
        ],
    ];
}

/**
 * Implements hook_preprocess_block().
 */
function mkbh_blocks_preprocess_block(&$variables) {
  // Use a bare template for the page's main content.
  if ($variables['block_html_id'] == 'block-system-main') {
    if ($term = menu_get_object('taxonomy_term', 2)) {
      $variables['classes_array'][] = drupal_html_class('container');
    }
  }
}
/**
 * Implements hook_views_pre_render().
 */
function mkbh_blocks_views_pre_render(&$view)
{
    //  if($view->name == 'article_mest_laeste' && $view->current_display == 'pane_article_mest_leste') {
    //    $nodesIds = [];
    //    foreach($view->result as $result) {
    //      $nodesIds[$result->nid] = $result->nid;
    //    }
    //
    //    if(!empty($nodesIds)) {
    //      \Drupal\mkbh_unique_node\DisplayedNodes\DisplayedNodesSessionStorage::getInstance()->addDisplayedNodeIDs($nodesIds);
    //    }
    //  }
}

/**
 * Callback for byens-liv-seneste-more/%/% route.
 *
 * @param $page
 * @param $type
 *
 * @return array
 *
 * @see mkbh_blocks_menu()
 */
function mkbh_block_byens_liv_seneste_load_more($page, $type)
{
    $seneste_block = mkbh_block_byens_rum_liv_seneste_content($type, $page);
    $commands = [];
    $commands[] = ajax_command_remove('.load-more');
    $commands[] = ajax_command_append('.mkbh-block-byens-' . $type . '-seneste', render($seneste_block));

    return ['#type' => 'ajax', '#commands' => $commands];
}

/**
 * Function for getting content for mkbh_block_byens_rum_liv_seneste block.
 *
 * @param int $page - page number for "load more" button.
 * @param $type - "rum" or "liv" for different pages.
 *
 * @return array
 *
 * @see mkbh_block_byens_liv_seneste_load_more()
 */
function mkbh_block_byens_rum_liv_seneste_content($type = 'liv', $page = 1)
{
    $fetcher = new Drupal\mkbh_blocks\Fetcher\NodeFetcher(\Drupal\mkbh_unique_node\DisplayedNodes\DisplayedNodesSessionStorage::getInstance());

    $limit = $type == 'liv' ? 9 : 10;

    $types_map = [
        'liv' => 6,
        'rum' => 5,
    ];

    $offset = ($page == 1) ? 0 : ($page - 1) * 6 + ($limit - 6);

    $nodes = $fetcher->fetchRecentArticles('article', [$types_map[$type]], 'any', $limit, $offset);
    $total_count = $fetcher->fetchRecentArticlesCount('article', [$types_map[$type]], 'any');

    $inAjax = FALSE;
    if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
        $inAjax = TRUE;
    }

    if ($type == 'liv') {
        $regions = [
            'top_left' => [
                '#theme' => 'mkbh_article_display__view_mode_large',
                '#main_image_view_mode' => 'homepage_large_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'top_medium_left' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'vertical',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
                '#trim_length' => 125,
            ],
            'top_medium_right' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'vertical',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
                '#trim_length' => 125,
            ],
            'bottom_randomized_row_1_region_1' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'horizontal',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_body' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
                '#trim_length' => 125,
            ],
            'bottom_randomized_row_1_region_2' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_randomized_row_1_region_3' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_randomized_row_2_region_1' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_randomized_row_2_region_2' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_randomized_row_2_region_3' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
        ];

        if ($inAjax) {
            unset($regions['top_left'], $regions['top_medium_left'], $regions['top_medium_right']);
        }
    } else {
        $regions = [
            'top_left' => [
                '#theme' => 'mkbh_article_display__view_mode_large',
                '#main_image_view_mode' => 'homepage_large_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'top_middle' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'vertical',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
                '#trim_length' => 125,
            ],
            'top_small_top' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_body' => FALSE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'top_small_bottom' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_body' => FALSE,
                '#show_breadcrumbs' => 'city_only',
            ],

            'bottom_medium_top_right' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'horizontal',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_body' => FALSE,
                '#show_breadcrumbs' => 'city_only',
                '#trim_length' => 125,
            ],
            'bottom_small_top_left_1' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_small_bottom_left_1' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],

            'bottom_medium_bottom_right' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'horizontal',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_body' => FALSE,
                '#show_breadcrumbs' => 'city_only',
                '#trim_length' => 125,
            ],
            'bottom_small_top_left_2' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_small_bottom_left_2' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
        ];

        if ($inAjax) {
            unset($regions['top_left'], $regions['top_middle'], $regions['top_small_top'], $regions['top_small_bottom']);
        }
    }

    $items = [];

    foreach ($regions as $region => $build) {
        if (is_array($nodes) && !empty($nodes)) {
            $build['#node'] = array_shift($nodes);
            $build['#adapter'] = new Drupal\mkbh_blocks\Adapter\NodeAdapterProxy($build['#node']);
            $items[$region] = $build;
        }
    }

    return [
        '#theme' => 'mkbh_block_byens_' . $type . '_seneste',
        '#items' => $items,
        '#load_more' => (($total_count - ($limit + $offset)) > 0) ? l(t('mere byens @type', ['@type' => $type]), 'byens-rum-liv-seneste-more/' . ($page + 1) . '/' . $type, ['attributes' => ['class' => ['use-ajax']]]) : '',
        '#attached' => [
          'js' => [
            libraries_get_path('jquery-match-height') . '/dist/jquery.matchHeight-min.js',
          ],
        ],
    ];
}

/**
 * Callback for byens-liv-seneste-more/% route.
 *
 * @param $page
 *
 * @return array
 *
 * @see mkbh_blocks_menu()
 */
function mkbh_block_opinion_seneste_load_more($page)
{
    $seneste_block = mkbh_blocks_get_opinion_seneste_content($page);
    $commands = [];
    $commands[] = ajax_command_remove('.load-more');
    $commands[] = ajax_command_append('.mkbh-block-opinion-seneste', render($seneste_block));

    return ['#type' => 'ajax', '#commands' => $commands];
}

/**
 * Function to get content for mkbh_block_opinion_seneste block.
 *
 * @param int $page - page number for "load more" button.
 *
 * @return array
 *
 * @see mkbh_block_opinion_seneste_load_more()
 */
function mkbh_blocks_get_opinion_seneste_content($page = 1)
{
    $fetcher = new Drupal\mkbh_blocks\Fetcher\NodeFetcher(\Drupal\mkbh_unique_node\DisplayedNodes\DisplayedNodesSessionStorage::getInstance());
    $limit = 11;
    $offset = ($page - 1) * $limit;

    $nodes = $fetcher->fetchRecentArticles('article', [8], 'any', $limit, $offset);
    $total_count = $fetcher->fetchRecentArticlesCount('article', [8], 'any');

    $inAjax = FALSE;
    if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
        $inAjax = TRUE;
    }

    $regions = [
        'top_large_left' => [
            '#theme' => 'mkbh_article_display__view_mode_large',
            '#main_image_view_mode' => 'homepage_large_image',
            '#show_shares_count' => FALSE,
            '#show_writer_name' => TRUE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#orientation' => 'horizontal',
            '#show_body' => FALSE,
        ],
        'top_middle_right' => [
            '#theme' => 'mkbh_article_display__view_mode_medium',
            '#orientation' => 'vertical',
            '#main_image_view_mode' => 'homepage_medium_image',
            '#show_shares_count' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
            '#show_body' => FALSE,
        ],
        'middle_middle_1' => [
            '#theme' => 'mkbh_article_display__view_mode_medium',
            '#orientation' => 'vertical',
            '#main_image_view_mode' => 'homepage_medium_image',
            '#show_shares_count' => FALSE,
            '#show_body' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
        ],
        'middle_middle_2' => [
            '#theme' => 'mkbh_article_display__view_mode_medium',
            '#orientation' => 'vertical',
            '#main_image_view_mode' => 'homepage_medium_image',
            '#show_shares_count' => FALSE,
            '#show_body' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
        ],
        'middle_middle_3' => [
            '#theme' => 'mkbh_article_display__view_mode_medium',
            '#orientation' => 'vertical',
            '#main_image_view_mode' => 'homepage_medium_image',
            '#show_shares_count' => FALSE,
            '#show_body' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
        ],
        'middle_small_1' => [
            '#theme' => 'mkbh_article_display__view_mode_small',
            '#show_body' => FALSE,
            '#show_shares_count' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
        ],
        'middle_small_2' => [
            '#theme' => 'mkbh_article_display__view_mode_small',
            '#show_body' => FALSE,
            '#show_shares_count' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
        ],
        'bottom_small_1' => [
            '#theme' => 'mkbh_article_display__view_mode_small',
            '#show_body' => FALSE,
            '#show_shares_count' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
        ],
        'bottom_small_2' => [
            '#theme' => 'mkbh_article_display__view_mode_small',
            '#show_body' => FALSE,
            '#show_shares_count' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
        ],
        'bottom_small_3' => [
            '#theme' => 'mkbh_article_display__view_mode_small',
            '#show_body' => FALSE,
            '#show_shares_count' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
        ],
        'bottom_small_4' => [
            '#theme' => 'mkbh_article_display__view_mode_small',
            '#show_body' => FALSE,
            '#show_shares_count' => FALSE,
            '#show_color' => TRUE,
            '#show_breadcrumbs' => FALSE,
            '#show_writer_name' => TRUE,
        ],
    ];

    if ($inAjax) {
        unset($regions['top_large_left'], $regions['top_middle_right']);
    }

    $items = [];

    foreach ($regions as $region => $build) {
        if (is_array($nodes) && !empty($nodes)) {
            $build['#node'] = array_shift($nodes);
            $build['#adapter'] = new Drupal\mkbh_blocks\Adapter\NodeAdapterProxy($build['#node']);
            $items[$region] = $build;
        }
    }

    return [
        '#theme' => 'mkbh_block_opinion_seneste',
        '#items' => $items,
        '#load_more' => (($total_count - ($limit + $offset)) > 0) ? l(t('Load more opinion'), 'opinion-seneste-more/' . ($page + 1), ['attributes' => ['class' => ['use-ajax']]]) : FALSE,
    ];
}

/**
 * Function for returning content for  mkbh_block_byens_rum_liv_laeser content.
 *
 * @param $type - type of page "rum" or "liv"
 *
 * @return array
 */
function mkbh_block_byens_rum_liv_laeser_content($type)
{
    $fetcher = new Drupal\mkbh_blocks\Fetcher\NodeFetcher(\Drupal\mkbh_unique_node\DisplayedNodes\DisplayedNodesSessionStorage::getInstance());

    $limit = 6;
    $types_map = [
        'liv' => 6,
        'rum' => 5,
    ];

    $nodes = $fetcher->fetchRecentArticlesLangLaeser('article', [$types_map[$type]], $limit);

    if ($type == 'liv') {
        $regions = [
            'top_small_1' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'top_small_2' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'top_medium' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'horizontal',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
                '#show_body' => FALSE,
            ],
            'bottom_small_1' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_small_2' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_medium' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'horizontal',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
                '#show_body' => FALSE,
            ],
        ];
    } else {
        $regions = [
            'top_medium' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'horizontal',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
                '#show_body' => FALSE,
            ],
            'top_small_1' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'top_small_2' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_medium' => [
                '#theme' => 'mkbh_article_display__view_mode_medium',
                '#orientation' => 'horizontal',
                '#main_image_view_mode' => 'homepage_medium_image',
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
                '#show_body' => FALSE,
            ],
            'bottom_small_1' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
            'bottom_small_2' => [
                '#theme' => 'mkbh_article_display__view_mode_small',
                '#show_body' => FALSE,
                '#show_shares_count' => FALSE,
                '#show_color' => TRUE,
                '#show_breadcrumbs' => 'city_only',
            ],
        ];
    }

    $items = [];

    foreach ($regions as $region => $build) {
        if (is_array($nodes) && !empty($nodes)) {
            $build['#node'] = array_shift($nodes);
            $build['#adapter'] = new Drupal\mkbh_blocks\Adapter\NodeAdapterProxy($build['#node']);
            $items[$region] = $build;
        }
    }

    return [
        '#theme' => 'mkbh_block_byens_' . $type . '_laeser',
        '#items' => $items,
    ];
}
