I have a plugin that adds a couple extra fields to com_content. I've already sorted out how to add the fields to the frontend editing form, so that they're displayed and saved appropriately, that is working fine for me.
What I'm trying to do is have users fill in one field, and then, when the form is submitted, get the data from that field, manipulate it, and save a variant of that to another field, and have both saved to the database.
For example. A user fills in the video_url field with "https://www.youtube.com/watch?v=uO59tfQ2TbA". When the form is submitted, I get the contents of video_url, manipulate it to isolate the youtube video ID, and then save that to video_id as "uO59tfQ2TbA", and add that to the data saved to the database.
I thought I could use the onContentBeforeSave plugin event, but I think I'm doing something wrong, though, because it's not working lol.
Here's what I've got so far. (to keep the logic simple and figure out how to actually save this second field, I'm currently just copying the first field into the second ... or attempting to.
public function onContentBeforeSave ($context, &$article, &$isNew)
{
$app = JFactory::getApplication();
$option = $app->input->get('option');
$layout = $app->input->get('layout');
if($option == 'com_content' && $layout == 'edit') {
$video_url = $_POST['jform']['attribs']['video_url'];
$video_id = $video_url;
$attribs->video_id = $video_id;
$article->attribs = json_encode($attribs);
}
}
Any help? I'm trying to figure this out as I go, haven't done this before.