Commit 435cc0df authored by marcvangend's avatar marcvangend

store settings on the entitydisplaymode using thirdpartysettings

parent 8a31d6fe
......@@ -5,10 +5,8 @@
* Allow fields to be rendered in blocks.
*/
use Drupal\Core\Field\FieldConfigBase;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\migrate_drupal\Plugin\migrate\Process\d6\FieldSettings;
define('FIELDBLOCK_STORAGE_STATIC', 'fieldblock_storage');
......@@ -54,37 +52,19 @@ function fieldblock_field_display_submit($form, FormStateInterface $form_state)
$bundle = $form['#bundle'];
$mode = $form['#mode'];
$config_name = 'fieldblock.' . $entity_type .'.'. $bundle;
$config = \Drupal::config($config_name);
$settings = array();
/** @var \Drupal\Core\Entity\EntityDisplayModeInterface $view_mode_config */
$view_mode_config = EntityViewDisplay::load($entity_type . '.' . $bundle . '.' . $mode);
$fields = $form_state->getValue('fields');
foreach ($fields as $field_name => $field) {
/** @var \Drupal\field\FieldInstanceConfigInterface $field_instance_config */
$field_instance_config = FieldInstanceConfig::load($entity_type . '.' . $bundle . '.' . $field_name);
if (!empty($field['fieldblock'])) {
$field_instance_config->setThirdPartySetting('fieldblock', $field_name, $form['fields'][$field_name]['human_name']['#markup']);
$field_instance_config->save();
}
$foo = 'bar';
}
if (empty($settings)) {
// This config may have existed before, so let's clean up a little.
$config->clear($mode);
if (count($config->get()) == 0) {
// There's nothing left in here; delete.
$config->delete();
if (isset($field['fieldblock']) && $field['fieldblock'] == 1) {
$view_mode_config->setThirdPartySetting('fieldblock', $field_name, $form['fields'][$field_name]['human_name']['#markup']);
}
else {
// Other view modes are still present; save.
$config->save();
else if ($view_mode_config->getThirdPartySetting('fieldblock', $field_name)) {
$view_mode_config->unsetThirdPartySetting('fieldblock', $field_name);
}
}
else {
$config->set($mode, $settings)->save();
drupal_set_message(t('One or more fields have been made available as block. Do not forget to <a href="!block_admin_url">assign the block(s) to a region</a>.', array('!block_admin_url' => url('admin/structure/block'))));
}
$view_mode_config->save();
}
///**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment