Skip to content

Conversation

@yanniboi
Copy link
Collaborator

No description provided.

@yanniboi yanniboi requested a review from andrewbelcher August 21, 2017 08:06
$source_field = $definition->getFieldStorageDefinition()->getSetting('source_field');

$value = $entity->{$source_field}->value;
$original_value = $entity->original->{$source_field}->value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use \Drupal\Core\Field\FieldItemBase::mainPropertyName rather than assuming value?

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks these are being overridden with no changes?

foreach ($items as $delta => $item) {
/* @var \Drupal\decoupled_auth_crm_tools\Plugin\Field\FieldType\StatusLog $item */
$values = $item->getValue();
if (is_array($values) && !empty($values['value'])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use $item->isEmpty()? And is that a scenario that's possible once you get to the formatter?

if (is_array($values) && !empty($values['value'])) {

$elements[$delta]['value'] = [
'#type' => 'html_tag',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be better if $elements['#type'] = 'item_list'; and the values were the #items?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might mess with other things as I think $elements[$delta] is the expected pattern...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatter can say it handles multiple values and then deal with the whole lot as one.

*
* Update status log fields.
*/
function decoupled_auth_crm_tools_entity_presave(EntityInterface $entity) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this not live in the field \Drupal\Core\Field\FieldItemListInterface::preSave?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I tried all of the fielditemlist hooks... Unless the field actually is set pre save, nothing on the fielditemlist gets triggered.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContentEntityStorageBase::invokeFieldMethod is invoked for each field on presave, I'm surprised this doesn't work and is worth checking again.

'#disabled' => $has_data,
];

// @todo Make this field a select field of existing fields on entity.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we do this, we need to filter the fields by appropriate ones. My suggestion would be ones where there is a main value and the main value is a string... We may want to put some similar validation somewhere else for programmatic fields, but not exactly sure where that should live...

foreach ($entity->getFieldDefinitions() as $field_name => $definition) {
/* @var \Drupal\Core\Field\FieldDefinitionInterface $definition */
if ($definition->getType() == 'status_log') {
$source_field = $definition->getFieldStorageDefinition()->getSetting('source_field');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put all of this logic inside the status log field list class.

/**
* {@inheritdoc}
*/
public function applyDefaultValue($notify = TRUE) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants