Commit 0f2242e6 authored by jrockowitz's avatar jrockowitz

Change block_field.id to block_field.plugin_id.

parent 23b83f20
......@@ -44,7 +44,7 @@ class BlockFieldFormatter extends FormatterBase {
'#plugin_id' => $block_instance->getPluginId(),
'#base_plugin_id' => $block_instance->getBaseId(),
'#derivative_plugin_id' => $block_instance->getDerivativeId(),
'#id' => $item->id,
'#id' => $item->plugin_id,
'content' => $block_instance->build(),
];
......
......@@ -41,15 +41,15 @@ class BlockFieldItem extends FieldItemBase implements BlockFieldItemInterface {
* {@inheritdoc}
*/
public static function mainPropertyName() {
return 'id';
return 'plugin_id';
}
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['id'] = DataDefinition::create('string')
->setLabel(t('ID'))
$properties['plugin_id'] = DataDefinition::create('string')
->setLabel(t('Plugin ID'))
->setRequired(TRUE);
$properties['settings'] = MapDataDefinition::create()
......@@ -64,7 +64,7 @@ class BlockFieldItem extends FieldItemBase implements BlockFieldItemInterface {
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'id' => [
'plugin_id' => [
'description' => 'The block plugin id',
'type' => 'varchar',
'length' => 255,
......@@ -76,7 +76,7 @@ class BlockFieldItem extends FieldItemBase implements BlockFieldItemInterface {
'serialize' => TRUE,
],
],
'indexes' => ['id' => ['id']],
'indexes' => ['plugin_id' => ['plugin_id']],
];
}
......@@ -90,10 +90,10 @@ class BlockFieldItem extends FieldItemBase implements BlockFieldItemInterface {
$block_manager = \Drupal::service('plugin.manager.block');
$options = [];
$definitions = $block_manager->getSortedDefinitions();
foreach ($definitions as $id => $definition) {
$options[$id] = [
foreach ($definitions as $plugin_id => $definition) {
$options[$plugin_id] = [
['category' => (string) $definition['category']],
['label' => $definition['admin_label'] . ' (' . $id . ')'],
['label' => $definition['admin_label'] . ' (' . $plugin_id . ')'],
['provider' => $definition['provider']],
];
}
......@@ -130,7 +130,7 @@ class BlockFieldItem extends FieldItemBase implements BlockFieldItemInterface {
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->get('id')->getValue();
$value = $this->get('plugin_id')->getValue();
return $value === NULL || $value === '';
}
......@@ -159,7 +159,7 @@ class BlockFieldItem extends FieldItemBase implements BlockFieldItemInterface {
* {@inheritdoc}
*/
public function getBlock() {
if (empty($this->id)) {
if (empty($this->plugin_id)) {
return NULL;
}
......@@ -167,7 +167,7 @@ class BlockFieldItem extends FieldItemBase implements BlockFieldItemInterface {
$block_manager = \Drupal::service('plugin.manager.block');
/** @var \Drupal\Core\Block\BlockPluginInterface $block_instance */
$block_instance = $block_manager->createInstance($this->id, $this->settings);
$block_instance = $block_manager->createInstance($this->plugin_id, $this->settings);
$plugin_definition = $block_instance->getPluginDefinition();
......
......@@ -32,7 +32,7 @@ class BlockFieldWidget extends WidgetBase {
*/
public static function defaultSettings() {
return [
'id' => '',
'plugin_id' => '',
'settings' => [],
] + parent::defaultSettings();
}
......@@ -48,12 +48,12 @@ class BlockFieldWidget extends WidgetBase {
$item = $items[$delta];
$field_name = $this->fieldDefinition->getName();
$configuration_id = $field_name . '-' . $delta . '-settings';
$settings_id = $field_name . '-' . $delta . '-settings';
$plugin_ids = $this->fieldDefinition->getSetting('plugin_ids');
$values = $form_state->getValues();
$item->id = (isset($values[$field_name][$delta]['id'])) ? $values[$field_name][$delta]['id'] : $item->id;
$item->plugin_id = (isset($values[$field_name][$delta]['plugin_id'])) ? $values[$field_name][$delta]['plugin_id'] : $item->plugin_id;
if (!empty($values[$field_name][$delta]['settings'])) {
$item->settings = $values[$field_name][$delta]['settings'];
}
......@@ -73,23 +73,23 @@ class BlockFieldWidget extends WidgetBase {
$options[$category][$id] = $definition['admin_label'];
}
$element['id'] = [
$element['plugin_id'] = [
'#type' => 'select',
'#title' => $this->t('ID'),
'#options' => $options,
'#empty_option' => $this->t('- None -'),
'#default_value' => $item->id,
'#default_value' => $item->plugin_id,
'#required' => $element['#required'],
'#ajax' => [
'callback' => [$this, 'configurationForm'],
'wrapper' => $configuration_id,
'wrapper' => $settings_id,
],
];
// Build configuration container.
$element['settings'] = [
'#type' => 'container',
'#attributes' => ['id' => $configuration_id],
'#attributes' => ['id' => $settings_id],
'#tree' => TRUE,
];
......@@ -138,7 +138,7 @@ class BlockFieldWidget extends WidgetBase {
$block_manager = \Drupal::service('plugin.manager.block');
$values = $form_state->getValues();
$plugin_id = NestedArray::getValue($values, $element['id']['#parents']);
$plugin_id = NestedArray::getValue($values, $element['plugin_id']['#parents']);
if (!empty($plugin_id) && $block_manager->hasDefinition($plugin_id)) {
// Clean up configuration settings.
......
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