Drupal EntityForm hooks - drupal-modules

I am using drupal Entity-Form module, I have successfully achieved the user interface part of it. But when i am trying to hook the Entity-form submission, I am not able to get any thing..
I have tried hook_form_alter(), hook_form_FORM_ID_alter(), but nothing.
Has any one achieved it...? I have tried all below:-
function form_submit_igs_entity_views_field_handlers_alter(array &$field_handlers){
echo "pankaj";
}
function _form_entityform_settings_alter(&$form, &$form_state, $form_id) {
echo "pankaj";
}
function form_submit_igs_entity_presave($entity, $type){
echo "pankaj";
}
function form_submit_igs_node_view_alter(&$build){
echo "pankaj";
}
function form_submit_igs_field_attach_submit($entity_type, $entity, $form, &$form_state){
echo "pankaj";
}
function form_submit_igs_form_alter(&$form, &$form_state, $form_id){
echo "pankaj";
}

Here's how I figured it out:
I wrote a hook_form_alter() function it looked like this
function hook_form_alter()(&$form, &$form_state, $form_id) {
dpm($form);
}
from that I could get a formID on the existing form & then get the appropriate name for the function.
Note you can also do:
function hook_form_entityform_edit_form_alter(&$form, &$form_state, $form_id) {
dpm($form);
}
To alter only entity forms.
in both instances hook is to be replaced by your module name. Install devel module to get dpm() function to work and not throw an error.
Hope this helps you figure out your issue.

Not sure what you want to archive, your description is not very good, but anyway.
To alter any entityform form you need to use, as by entityform_forms(), $machine_name . '_entityform_edit_form' as form ID, so your function will look like this some_func_form_YOUR_ENTITY_FORM_NAME_entityform_edit_form_alter().

I have used hook_form_FORM_ID_alter(), you must use your particular entityform's machine name plus _entityform after the machine name. For example if your entityform's machine name is "myentityform" and your module name is "mymodule", the hook_form_FORM_ID_alter will be:
/**
* Implements hook_form_FORM_ID_alter().
*/
function mymodule_form_myentityform_entityform_edit_form_alter(&$form, &$form_state, $form_id)
{
// Your codes
}

Related

Association is in database, but can't be retrieved via DAL. Will retrieve empty array of associations

I am following the advanced developer tutorial (https://docs.shopware.com/en/shopware-platform-dev-en/how-to/indepth-guide-bundle).
Currently I'm at step 7, and according to the tutorial what I've made so far should work.
But it doesn't.
In the database it shows the association, but I can't retrieve them from the repository.
You have to add the association to the Criteria.
$criteria->addAssociation("name_of_association")
Without it, the associations come as null.
Okay, turns out I switched up two parameters by accident. When I set them correctly it worked as it should.
<?php declare(strict_types=1);
namespace Swag\BundleExample\Core\Content\Product;
use Shopware\Core\Content\Product\ProductDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Swag\BundleExample\Core\Content\Bundle\Aggregate\BundleProduct\BundleProductDefinition;
use Swag\BundleExample\Core\Content\Bundle\BundleDefinition;
class ProductExtension extends EntityExtension
{
public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new ManyToManyAssociationField(
'bundles',
BundleDefinition::class,
BundleProductDefinition::class,
'product_id',
'bundle_id'
))->addFlags(new Inherited())
);
}
public function getDefinitionClass(): string
{
return ProductDefinition::class;
}
}
I'm talking about the 'product_id' and 'bundle_id'. In my case I had the 'product_id' as the last parameter.

How to get entity from the argument and create if condition in Dialogflow Inline editor for fulfilment

I am completely new to Dialogflow and nodejs. I need to get the entity value from the argument to the function (agent) and apply if the condition on that. How can I achieve this?
I am trying below but every time I get else condition become true.
I have created an entity named about_member.
function about_member_handeller(agent)
{
if(agent.about_member=="Tarun")
{
agent.add('Yes Tarun');
}
else
{
agent.add("No tarun");
}
}
Please help.
In such cases, you may use console.log to help unleash your black box, like below:
function about_member_handeller(agent) {
console.log(JSON.stringify(agent, null, 2));
if(agent.about_member=="Tarun") {
agent.add('Yes Tarun');
}
else {
agent.add("No tarun");
}
}
JSON.stringfy() will serialize your json object into string and console.log will print the same on the stdOut. So once you run your code this will print the object structure for agent and after which you will know on how to access about_member. Because in the above code it's obvious that you are expecting about_member to be a string, but this code will let you know on the actual data in it and how to compare it.
To get the parameter you can use the following;
const valueOfParam = agent.parameters["parameterName"];

Angular JS Controller scope and private functions and variables

I'm having an issue, I did a Little application a few months ago in angular, but in order to extend my knowledge about angular I decide to add a funcionality and complexity to my code.
So no I inject the module and the controller and I use app config and ng-route.
Now I have something like this:
var app = angular.module('myApp',['ngRoute']);
app.config(appConfig);
app.controller('TestController', ['$http', TestController])
function appConfig($routeProvider){
$routeProvider.when('/', {
templateUrl: './test.html',
controller: 'TestController',
controllerAs: 'my'
});
}
function TestController($http ) {
this.statusForm = 'Incompleto';
a();
}
function a(){
statusForm='Finalizado';
¿HOW DO I ACCES STATUSFORM TO CHANGE ITS VALUE IN TestController?
}
So that's my question, how do I change from a private function called inside the cotroller without $scope.
Is there anyway to refer the testcontroller function's scope?
Finally I found an answer to my question. I feel a bit of shame because the answer is a bit simple. I should figured it out much sooner and easier than I did.
Ok, I'm explaining it, originally i had this:
function TestController($http ) {
this.statusForm = 'Incompleto';
a();
}
function a(){
statusForm='Finalizado';
¿HOW DO I ACCES STATUSFORM TO CHANGE ITS VALUE IN TestController?
}
And the problema was that statusform was not accesiblo at function a, before when it was using $scope it was accesible.
function TestController($http ) {
this.statusForm = 'Incompleto';
a(**this**);
}
function a(**padre**){
**padre**.statusForm='Finalizado';
}
So I've changed it this way(see changes between **) and now it Works. I thought i would have some angulars way to not to send the parameter to the function "a", but i didn't find any.
Any way this way Works.
If anyone has ever the same doubt i hope this help. Greetings.

Load Controller With Parameter Opencart

I have created one controller inside catalog/controller/module/same_collection.php
Inside that :
class ControllerModuleSameCollection extends Controller {
//User Product History
public function index($product_id) {
echo $product_id;
}
}
I have try to call it inside another controller like this
$data['same_color'] = $this->load->controller('module/same_color' ,['product_id' => 2] );
and I try to by access it using url like this
mydomain.com/index.php?route=module/same_collection&product_id=2
but it's not working.
Please help!!!
It seems like you have not created your module properly. Make sure your module's setting is saved in module table . If your module's code is not there in the table then you won't get any parameter in your index() method.

Black-hole error when route pointed to a class that extends plugin and uses extended class

In routes I have
Router::connect('/opauth-complete/*', array('controller' => 'app_users', 'action' => 'opauth_complete'));
If I change pointer to controller app_users with anything else and create controller everything works with no error. But I need it to work with AppUsersController.
AppUsersController looks like this
App::uses('UsersController', 'Users.Controller');
class AppUsersController extends UsersController {
public function beforeFilter() {
parent::beforeFilter();
$this->User = ClassRegistry::init('AppUser');
}
// ...
// ...
public function opauth_complete() {
die(1);
}
// ...
// ...
}
So, plugin is CakeDC Users and another plugin that goes to /example/callback after /example/auth/facebook is Opauth plugin.
Error message looks like this
The request has been black-holed
Error: The requested address '/example/opauth-complete' was not found on this server.
This is perfectly possible to make these two plugins work together; when browser points to /example/auth/facebook, it redirects to /example/auth/callback and somehow it needs opauth-complete route to link to specific method.
All works if not pointed to app_users that extends plugin, uses plugin. Does not work only with this case. How can users of these two plugins get around such situation.
I solved it by disabling Security component on Opauth action in my AppUsersController. Thing is that Opauth transfers data using POST and you should either change a method of it (ie: use Sessions, GET) or disable Security component.
For a method change use this in your bootstrap.php or core.php
Configure::write('Opauth.callback_transport', 'session'); // you can try 'get' too
To follow my approach add this to a controller where error occurs and where you place your opauth_complete method
public function beforeFilter() {
// ...
if (isset($this->Security) && $this->action == 'opauth_complete') {
$this->Security->validatePost = false;
$this->Security->csrfCheck = false;
}
// ...
}
P.S. Changing method to Sessions has its drawbacks, you can take a look at comments here at Github Opauth issue #16

Resources