I think a plugin system for detecting the current environment would be really helpful.
While a lot of people would opt to use URL matching to discover the current environment, I can see other methods being used:
- a config override in settings.php
- a setting in \Drupal::state()
- a system environment variable (retrieved via getenv()) - e.g. set by a CI script targetting a specific environment
- ...
Together with the patch to default_content mentioned above, this MR allows custom_field data to be exported by default_content, and imported by default_content import OR core's DefaultContent API, used by recipes.
Attached is a patch file for the current state of the MR, useful for Composer based patching workflows.
A patch has been added to default_content module, to make sure the Default Content exported YML files use the UUID identifiers of referenced entities within a custom_field field, rather than their (numeric) entity ID.
The patch can be found at
✨
Add support for custom_field module
Active
On the import side of things, there is a patch for custom_field that makes this work: 📌 Support Drupal core DefaultContent API Active .
Created an MR that updates custom_field data in the Default Content export for referenced entities.
Original output without this MR:
field_my_custom_field:
-
label: 'Exported label'
image: 21 # Some random file ID
image__width: 1024
image__height: 1024
image__alt: Sunset
image__title: ''
file: 22 # Some random file ID
term: 4 # Some random taxonomy term ID
After applying this MR. this becomes:
field_my_custom_field:
-
label: 'Exported label'
image: aa6340f0-0006-4f31-9f2d-5595f5cce028
image__width: 1024
image__height: 1024
image__alt: Sunset
image__title: ''
file: c36ea199-cd17-4fe5-bec7-beef1ffb51b4
term: 78ae1ee7-f2d4-4fc0-871e-1af92730df3b
The referenced UUIDs also get added as a dependency to the "_meta" definition.
svendecabooter → created an issue.
svendecabooter → created an issue.
Can you try if the patch in 📌 Set block entity values via FieldTextExtractor plugins Active resolves this issue for you?
A better fix for this issue is implemented in 📌 Set block entity values via FieldTextExtractor plugins Active
Tested with the changed that got committed into the ai_translate module.
Everything seems to work now!
MR added for this functionality.
Also attaching as a patch file, for Composer based patching workflows.
svendecabooter → created an issue.
Seems related to https://www.drupal.org/project/ai/issues/3529669 ✨ Handle link field translation as well Active
As reported in 🐛 [5.0.0-alpha3] Menu items do not get is-active class Active , this MR fixes the issue for me in ui_suite_daisyui for me, after adding some extra logic in the menu component of that theme.
I think having active menu items is pretty basic expected behaviour for a theme, so would be good to get this included sooner rather than later. Having to patch both a module and theme to get a visual indicator of the active menu item, isn't the best situation for getting adoption IMHO. Therefor I took the liberty to increase the priority of this issue. Feel free to lower priority if you disagree.
I fixed this by applying the patch in
✨
Add ability to track active menu items in menu source
Active
and adding the following to the ui_suite_daisyui:menu
component:
(...)
{% for item in items %}
<li{{ (not item.url and loop.first) ? ' class="menu-title"' : '' }}>
{% set item_attributes = item.attributes|default(create_attribute()) %}
{# Start adding class for menu active trail #}
{% if item.in_active_trail %}
{% set item_attributes = item_attributes.addClass('menu-active') %}
{% endif %}
{# End adding class for menu active trail #}
{% if item.url %}
(...)
Not sure if this logic can already be incorporated into ui_suite_daisyui, while waiting on its commit in ui_patterns.
It would be good to have this already in place by the time ui_patterns gets updated, but not sure what the policy is there...
I'm not sure if this is the right place for this feature request, but I would propose to add an alter hook to the getFeaturedPageActions() method.
In my case, I want a custom entity to have another "featured action", rather than the edit form.
Currently I don't see a way to achieve this.
IMHO core should provide sane defaults, but allow the option for contrib / custom module to change the default behaviour.
The logic in the MR now seems to work for most of the custom_field property types I have tested.
Still WIP:
- Link field is a challenge. The link itself gets translated currently, since it's a string. However source link
https://google.com
gets translated in my OpenAI instance to\nhttps://google.com\n
, where the extra newline characters mess up the data. Ideally the link itself shouldn't go to translation... - Image alt / title texts do not get translated yet, because their property is not a string DataType, but rather an entity reference...
Thanks for the commit!
We use Single Directory Components in our themes, so using a custom template override allows us to render the custom_field through a SDC component.
E.g.:
{{ include('themename:card', {
label: item['label'],
title: item['title'],
subtitle: item['subtitle']
body: item['body'],
}, only) }}
svendecabooter → created an issue.
As per conversation in #ai on Slack, moving this to 1.2.x branch, since it's a new / extra feature.
As per conversation in #ai on Slack, moving this to 1.2.x branch, since it's a new / extra feature.
I'm encountering the same issue when using Heroicons.
Could a new release be tagged with this improvement?
Patch file included for composer-based patching workflows.
OK I think this should be doable, but it would require the patch in
✨
Don't hardcode 'value' key for textual field translation
Active
to be committed first.
Not sure how fast that can happen, so this extra plugin probably won't be committed into custom_field, before that issue is resolved.
I'll try to get the MR here working in combination with that issue, and hopefully keep it as simple as possible.
Currently there is some logic that checks if a custom_field subfield / property is translatable or not.
But ideally that should check if that subfield is textual or not. Is there some mechanism in place to do that?
I guess just doing checks on CustomFieldType plugin instances? I.e. StringType & StringLongType?
svendecabooter → created an issue.
Created a merge request that abstracts out the hardcoded 'value' logic.
If the FieldTextExtractor plugin returns an array of type ['value' => 'Some text']
in their extract() method, everything should keep working as before. But if the FieldTextExtractor plugin returns more dynamic properties, e.g. via the custom_field module, this would now work.
Example data in the extract() method for a "custom_field" FieldTextExtractor would then be:
['question' => 'Some question'. 'answer' => 'Some answer']
The changed logic applies both to the translation via the UI (Controller class) or via Drush. Ideally, both should be refactored to abstract out logic that is the same in both implementations, to allow less code duplication, but that seems out of scope for this issue.
Thanks for giving this some thought / review.
Thanks for the feedback. I'm working on a fix. Might take me a few days to push some code though...
Linking issue in AI module, that complicates this functionality.
svendecabooter → created an issue.
svendecabooter → created an issue.
I applied the MR logic from
✨
Add ability to track active menu items in menu source
Active
.
Then in ui_suite_daisyui:menu
component, I add a check:
{% if item.in_active_trail %}
<!-- Try adding extra class here -->
{% endif %}
That doesn't seem to work... Maybe I'm missing some additional context
svendecabooter → changed the visibility of the branch 3528586-support-drupal-core to hidden.
OK it should be possible after all I think.
Say we can integrate with the contrib Default Content module, to produce output as follows:
field_logos:
-
logo:
entity_type: 'media'
entity: eab657e0-3320-41d2-ab4e-53a09b397758
link: 'https://google.com'
link__title: ''
link__options: { }
(if not possible, worst case we need to document the exported YAML files have to be manually edited).
Then in CustomFieldEntityReference::setValue(). we can do something like:
/**
* {@inheritdoc}
*/
public function setValue($value, $notify = TRUE): void {
$entity = $value['entity'] ?? NULL;
// START ADDED LOGIC.
if (is_array($value)) {
if ($value['entity_type'] && Uuid::isValid($value['entity'])) {
$entity = \Drupal::entityTypeManager()->getStorage($value['entity_type'])->loadByProperties(['uuid' => $value['entity']]);
$entity = !empty($entity) ? current($entity) : NULL;
}
}
// END ADDED LOGIC.
if ($entity instanceof EntityInterface) {
...
}
I can spend some time to look further into this, but am currently time restrained, so just doing some braindump here.
Will try to elaborate on it next week.
Let me know if it would be a workable solution to extend the setValue() logic, for the use case of default content exports / imports.
Did some more digging, and it seems the datatype used in custom_field module is "CustomFieldEntityReference", which does not inherit from core "EntityReference" data type, so guess this will never work :'(
svendecabooter → created an issue.
1.2.2 has been released now
Thanks a lot!
Thanks - committed!
svendecabooter → created an issue.
Thanks for the fix, and sorry for the delay in committing.
Thanks for the fix.
Committed now.
Thanks for looking into this sarvjeetsingh.
It hadn't occurred to me that this could be the source of the issue.
Fix in MR resolves the issue for me.
Added MR that adds this functionality + a patch file for Composer-based patching workflows.
Thanks for considering merging this functionality.
svendecabooter → created an issue.
svendecabooter → created an issue.
Merge request added.
This probably also can be committed to 1.0.x and 1.2.x branch, but I made the MR against 1.1.x, since I'm actively working with that branch.
svendecabooter → created an issue.
Added patch file for the current state of the MR, for composer based patching workflows.
I added a MR to add this functionality.
Whether or not the Provider Configuration fieldset is open by default or not, is managed via config. The default setting for this config is to remain open, to keep backwards compatibility.
svendecabooter → made their first commit to this issue’s fork.
EDIT: seems to be unrelated to this patch, because I'm getting the same errors when patch is not applied.
Tested with OpenAI, and getting the following errors:
Warning: Undefined array key "fids" in Drupal\media_library\Form\FileUploadForm->validateUploadElement() (line 212 of /var/www/html/web/core/modules/media_library/src/Form/FileUploadForm.php)
ypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 212 of /var/www/html/web/core/modules/media_library/src/Form/FileUploadForm.php).
Haven't investigated the root cause yet...
All code review issues have been fixed, and extra explanation has been provided.
Setting this to Needs Review.
Thanks for the bug report, MR and review! Merging now.
Added a patch file, to be used in Composer-based patching workflows.
svendecabooter → created an issue. See original summary → .
Rebased the MR on current 11.x to resolve merge conflict.
svendecabooter → made their first commit to this issue’s fork.
This looks like a duplicate of ✨ Provide config action to set editor plugin configuration Active ?
svendecabooter → changed the visibility of the branch 3526978-add-providerid-context-1.1.x to hidden.
Created 2nd branch with same commit - branched from 1.1.x - since I needed that for my testing purposes.
Ah yes I did add the CSS like in #9 - forgot to document here.
@anjaliprasannan shouldn't the MR be against 1.1.x branch?
Not sure what the branching strategy for AI is exactly, but seems to me active dev is against 1.1.x now.
@sarvjeetsingh:
I'm not sure if that would work - I'm still tipping my toes into how all of this works...
It would be something like this, in the ChatOutput constructor?:
if ($normalized instanceof StreamedChatMessageIteratorInterface) {
$normalized->triggerEvent();
}
In my initial testing, that doesn't seem to work. I then get the same error as in the tests:
TypeError: Drupal\ai\Event\PostStreamingResponseEvent::__construct(): Argument #1 ($request_thread_id) must be of type string, null given
Not sure if that's something that also needs to be fixed, or if this means this approach is not workable...
svendecabooter → created an issue. See original summary → .
Basic integration logic has been committed in 1.0.x branch, but still needs some work.
Test PromptJsonDecoderTest
seems to fail now, because \Drupal\ai\Event\PostStreamingResponseEvent::__construct
doesn't receive a request_thread_id string in its constructor.
Not sure if this value is NULL in this test by design, or by accident.
If by design, then the PostStreamingResponseEvent $request_thread_id
parameter should be allowed to be nullable?
+1 - this fix is needed for ✨ Abstract token usage support Active to work.
Added related issues in AI module, that need to be fixed first, before both token usage for both regular chat and streamed chat can be captured.
MR now triggers the event, when the StreamedChatMessageIterator object gets destructed.
svendecabooter → created an issue.
Seems like the failure of PostStreamingResponseEvent not being triggered, is a separate issue.
See
🐛
PostStreamingResponseEvent never gets triggered
Active
.
The code in this MR can probably be already reviewed, but will not be functional until this other issue is fixed first.
svendecabooter → created an issue.
Thanks for the merge.
I guess we can now create followup tickets, so different local sites can request to merge in their own config_split.config_split.la_[LOCAL_SITE].yml
and appropriate config/la_[LOCAL_SITE]
config split folder.
Thanks for the added logic sarvjeetsingh.
I am unable to make this work on my local installation though, as mentioned above.
Test scenario:
- Enable AI CKEditor integration module
- Add AI button to CKEditor
- Enable "Fix spelling" for example
- Select a text in CKEditor that needs spelling fixes.
- The action gets performed, but my debugger never enters the method `\Drupal\ai\OperationType\Chat\StreamedChatMessageIterator::triggerEvent`
Can also be tested by installing dev version of https://www.drupal.org/project/ai_usage_limits → module, and configuring it with token usage limits. The usage stats will not go up in the test scenario mentioned above, even though they should...
svendecabooter → created an issue.
svendecabooter → created an issue.
Fixed in 1.0.x