Typo3 8.7 return a GLOBAL be_user value from a TCA Override page - typo3-8.x

I have created a new back-end variable called "userval".
I can reference this value in any controller by simply calling:
$GLOBALS['BE_USER']->user['userval']
However I need to get this value from another extensions, via the TCA/Overrides/tt_content.php page. The above code doesn't work here (I receive an empty value). Is it possible to access the BE_USER values from tt_content.php?

Update - I didn't manage to figure it out but I found a better solution that might work for others.
I needed this information because I wanted to return a list of items from a table that was linked to the field "userval". But the example below has been simplified for more general use..
I discovered that tt_content.php can have data passed directly to it via a controller. In the tt_content.php file, add the following:
'tx_some_example' =>
array(
'config' =>
array(
'type' => 'select',
'renderType' => 'selectSingle',
'items' => array (),
'itemsProcFunc' => 'SomeDomain\SomeExtensionName\Controller\ExampleController->getItems',
'selicon_cols' => 8,
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
'exclude' => '1',
'label' => 'Some example',
),
...note the "itemsProcFunc" line. This references returned data from the ExampleController.
In the ExampleController, here's how you can send the data into tt_content.php:
public function getItems($config){
//Sample data - this could be a DB call, a list in a folder, or a simple array like this
$sampleArray[
"id1" => "ID 1 Label",
"id2" => "ID 2 Label",
"id3" => "ID 3 Label",
];
$optionList = [];
$count=0;
//Cycle through each item, and add it to the desired dropdown list
foreach ($sampleArray as $id => $label) {
$optionList[$count] = [0 => $label, 1 => $id];
$count++;
}
//Pass the data back to the tt_content.php page
$config['items'] = array_merge($config['items'], $optionList);
return $config;
}

Related

EchoSign Embedd Widget with multiple signers

I want to embedd a widget in my application and be able to add 2 signers(recepients) to it without the sender required to sign the document.
The EchoSign docuemtation says that
"In the case of a reusable document that needs to be signed by multiple people, it is more efficient to call createEmbeddedWidget once and then call personalizeEmbeddedWidget for each signer."
I've tried this method but when I call the personalizeEmbeddedWidget function second time, it replaces the first recepient with the latest one instead of adding a new.
code:
$r = $s->createEmbeddedWidget(array(
'apiKey'=>ApiKey,
'widgetInfo'=>array(
'name'=>'Contract',
'fileInfos' => array(
'FileInfo' => array(
array(
'file' => $file2,
'fileName' => $filename2,
'mimeType' => 'text/html',
),
)
),
'widgetCompletionInfo'=>array(
'url'=> return-to-url,
'deframe'=> true,
),
'signatureFlow'=>'SENDER_SIGNATURE_NOT_REQUIRED',
)
));
if($r->embeddedWidgetCreationResult->success == 1){
$widgetCreationScript = $r->embeddedWidgetCreationResult->javascript;
$re = $s->personalizeEmbeddedWidget(array(
'apiKey'=>$ApiKey,
'widgetJavascript' => $widgetCreationScript,
'personalizationInfo' => array(
'email' => 1st_email_address,
)
));
$widgetScript = $re->embeddedWidgetCreationResult->javascript;
$docKey = $r->embeddedWidgetCreationResult->documentKey;
$re1 = $s->personalizeEmbeddedWidget(array(
'apiKey'=>$ApiKey,
'widgetJavascript' => $widgetScript,
'personalizationInfo' => array(
'email' => 2nd_email_address,
)
)); }
The version19 release provides a solution to this problem by adding the ability to add "counter signers" to a widget.
After the first signer completes the widget, the subsequent signer(s) get an email when it is their turn to sign.
But you can't have 2 signers sign a specific contract at the same time using the same link/screen.

Drupal Block not showing on the page

$blocks['onemore'] = array(
'info' => t('onemore'),
'status' => TRUE,
'region' => 'content',
'weight' => 0,
'cache' => DRUPAL_NO_CACHE,
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => 'admin/structure/nodequeue/1/view/1',
);
Problem - The above block shows up and works perfectly and as expected at 'admin/structure/nodequeue/1/view/1'
My problem is that I need to declare dynamic amounts of blocks based on the users inputs. So I wrote a db fetch and for each loop.
If I do this then the block shows up in 'admin/modules' but the it is not in 'content' region for the seven theme. As I want to show it there.
I have double checked the values and even the admin/structure/block/manage/xdmp/onemore/configure has the value but the region is not selected.
I am assuming there is some conflict in the for each loop or the db query. Please advice your thoughts on it.
function xdmp_block_info() {
$blocks = array();
// Here we are going to do a db query so that I can get a list of
// block ids to declare
$resultxdmp = db_query("
SELECT * FROM xdmp_container_list ");
foreach($resultxdmp as $resultRecords)
{
$xdmp_nodeque_id_to_display =(int)$resultRecords->xdmp_nodequeue_id;
$xdmp_nodeque_id_to_display = intval($xdmp_nodeque_id_to_display);
$xdmp_path_to_show_block = 'admin/structure/nodequeue/'.$xdmp_nodeque_id_to_display.'
/view/'.$xdmp_nodeque_id_to_display.'';
$xdmp_machinenameofblock=(string)$resultRecords->xdmp_container_machine_name;
$xdmp_nameofblock=(string)$resultRecords->xdmp_container_name;
$blocks[$xdmp_machinenameofblock] = array(
'info' => t($xdmp_nameofblock),
'status' => TRUE,
'region' => 'content',
'weight' => 0,
'cache' => DRUPAL_NO_CACHE,
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => $xdmp_path_to_show_block,
);
} // end for for each
return $blocks;
}
cheers,
Vishal
Are you sure the 'content' region is valid? If it's not, it of course can't show up :)

Why are Symfony2 validation propertyPath valus in square brackets?

I am validating some values:
$collectionConstraint = new Collection(array(
'email' => array(
new NotBlank(),
new Email(),
),
'password' => array(
new NotBlank(),
new MinLength(array('limit' => 6)),
new MaxLength(array('limit' => 25)),
),
));
$data = array('email' => $this->getRequest()->get('email'), 'password' => $this->getRequest()->get('password'));
$errors = $this->get('validator')->validateValue($data, $collectionConstraint);
But for some reason the fields (propertyPath) are stored with square brackets - I'd like to understand why Sf does that. I have to manually remove all the brackets which seems absurd so I think I am missing some functionality somewhere.
Dump of $errors:
Symfony\Component\Validator\ConstraintViolationList Object
(
[violations:protected] => Array
(
[0] => Symfony\Component\Validator\ConstraintViolation Object
(
[messageTemplate:protected] => This value should not be blank
[messageParameters:protected] => Array
(
)
[root:protected] => Array
(
[email] =>
[password] =>
)
[propertyPath:protected] => [email]
[invalidValue:protected] =>
)
[1] => Symfony\Component\Validator\ConstraintViolation Object
(
[messageTemplate:protected] => This value should not be blank
[messageParameters:protected] => Array
(
)
[root:protected] => Array
(
[email] =>
[password] =>
)
[propertyPath:protected] => [password]
[invalidValue:protected] =>
)
)
)
Even the toString function is useless.
"[email]: This value should not be blank","[password]: This value should not be blank"
Property paths can map either to properties or to indices. Consider a class OptionBag which implements \ArrayAccess and a method getSize().
The property path size refers to $optionBag->getSize()
The property path [size] refers to $optionBag['size']
In your case, you validate an array. Since array elements are also accessed by index, the resulting property path in the violation contains squared brackets.
Update:
You don't have to manually remove the squared brackets. You can use Symfony's PropertyAccess component to map errors to an array with the same structure as your data, for example:
$collectionConstraint = new Collection(array(
'email' => array(
new NotBlank(),
new Email(),
),
'password' => array(
new NotBlank(),
new MinLength(array('limit' => 6)),
new MaxLength(array('limit' => 25)),
),
));
$data = array(
'email' => $this->getRequest()->get('email'),
'password' => $this->getRequest()->get('password')
);
$violations = $this->get('validator')->validateValue($data, $collectionConstraint);
$errors = array();
$accessor = $this->get('property_accessor');
foreach ($violations as $violation) {
$accessor->setValue($errors, $violation->getPropertyPath(), $violation->getMessage());
}
=> array(
'email' => 'This value should not be blank.',
'password' => 'This value should have 6 characters or more.',
)
This also works with multi-dimensional data arrays. There the property paths will be something like [author][name]. The PropertyAccessor will insert the error messages in the same location in the $errors array, i.e. $errors['author']['name'] = 'Message'.
PropertyAccessor's setValue is no real help because it cannot handle multiple violations for a single field. For instance, a field might be shorter than a constraint length and also contain illegal characters. For this, we would have two error messages.
I had to create my own code:
$messages = [];
foreach ($violations as $violation) {
$field = substr($violation->getPropertyPath(), 1, -1);
$messages[] = [$field => $violation->getMessage()];
}
$output = [
'name' => array_unique(array_column($messages, 'name')),
'email' => array_unique(array_column($messages, 'email')),
];
return $output;
We manually strip the [] characters from the property path and create an
array of arrays of fields and corresponding messages. Later we transform the
array to group the messages by fields.
$session = $request->getSession();
$session->getFlashBag()->setAll($messages);
In the controller, we add the messages to the flash bag.

hook_load/hook_view not called

I have a module with four node types declared. My problem is, hook_load, hook_view is never called. I used drupal_set_message to find out if certain hook is being called. And I found out hook_load, hook_view isn't. Just to give you clear picture, here's my structure of hook_load
HERE'S UPDATED ONE
function mymodule_node_info(){
return array(
'nodetype1' => array(
'name' => t('nodetype1'),
'module' => 'mymodule_nodetype1',
'description' => t('....'),
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => TRUE,
'body_label' => t('Body'),
),
'nodetype2' => array(
......
'module' => 'mymodule_nodetype2',
......
),
'nodetype3' => array(
......
'module' => 'mymodule_nodetype3',
......
),
'nodetype4' => array(
......
'module' => 'mymodule_nodetype4',
.......
),
);
}
function mymodule_nodetype1_load($node){
$result = db_query('SELECT * from {nodetype1table} WHERE vid = %d'
$node->vid
);
drupal_set_message("hook_load is provoked.","status");
return db_fetch_object($result);
}
I don't know why it is not called. I wrote this code base on drupal module writing book and follow the instructions. I've tried sample code from that book and it works ok. Only my code isn't working. Probably because of multiple node types in one module. Any help would be highly appreciated.
Your code doesn't work because hook_load() and hook_view() aren't module hooks: they're node hooks. The invocation is based off of content type names, not module names.
So, first you need to have declared your content types using hook_node_info():
function mymodule_node_info() {
$items = array();
$items['nodetype1'] = array(
'name' => t('Node Type 2'),
'module' => 'mymodule_nodetype1',
'description' => t("Nodetype 1 description"),
);
$items['nodetype2'] = array(
'name' => t('Node Type 2'),
'module' => 'mymodule_nodetype2',
'description' => t("Nodetype 2 description"),
);
$items['nodetype3'] = array(
'name' => t('Node Type 2'),
'module' => 'mymodule_nodetype3',
'description' => t("Nodetype 3 description"),
);
return $items;
}
Then, you need to use the name of the module you specified for each content type declared in hook_node_info() for your node hooks. That is, mymodule_nodetype1_load(), mymodule_nodetype2_view(), etc.
Edit
If you're trying to have a non-node based module fire when a node is viewed or loaded, you need to use hook_nodeapi():
function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'view':
mymodule_view_function($node);
break;
case 'load':
mymodule_load_function($node);
break;
}
}
Replace mymodule_load_function() and mymodule_load_function() with your own custom functions that are designed to act on the $node object.
Edit 2
Besides the syntax error in your hook_load() implementations, there's a piece of your code outside of what you're providing that's preventing the correct invocation. The following code works (if you create a nodetype1 node, the message "mymodule_nodetype1_load invoked" appears on the node): perhaps you can compare your entire code to see what you're missing.
function mymodule_node_info() {
return array(
'mymodule_nodetype1' => array(
'name' => t('nodetype1'),
'module' => 'mymodule_nodetype1',
'description' => t('....'),
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => TRUE,
'body_label' => t('Body'),
),
'mymodule_nodetype2' => array(
'name' => t('nodetype2'),
'module' => 'mymodule_nodetype2',
'description' => t('....'),
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => TRUE,
'body_label' => t('Body'),
),
);
}
function mymodule_nodetype1_form(&$node, $form_state) {
// nodetype1 form elements go here
return $form;
}
function mymodule_nodetype2_form(&$node, $form_state) {
// nodetype2 form elements go here
return $form;
}
function mymodule_nodetype1_load($node) {
$additions = new stdClass();
drupal_set_message('mymodule_nodetype1_load invoked');
return $additions;
}
function mymodule_nodetype2_load($node) {
$additions = new stdClass();
drupal_set_message('mymodule_nodetype2_load invoked');
return $additions;
}
If you're not reseting your environment after changes to your module, you might be running into caching issues. You should test your code in a sandbox environment that can be reset to a clean Drupal installation to ensure you're not focusing on old cruft from previous, incorrect node implementations.
Additionally, you should only be using hook_nodeapi() if you are trying to act on content types that are not defined by your module. Your content types should be using the node hooks (hook_load(), hook_view(), etc.).
Finally, it may be the case that you're using the wrong hooks because you're expecting them to fire in places they are not designed to. If you've gone through everything above, please update your post with the functionality you're expecting to achieve and where you expect the hook to fire.
I found the culprit why your code doesn't work. It's because I was using the test data created by the old codes. In my old codes, because of node declaration inside hook_node_info uses the same module value, I could only create one hook_form implementation and use "switch" statement to return appropriate form. Just to give you clear picture of my old codes-
function mymodule_node_info(){
return array(
'nodetype1' => array(
.....
'module' => 'mymodule',
.....
),
'nodetype2' => array(
......
'module' => 'mymodule',
......
),
.......
);
}
function mymodule_form(&$node, $form_state){
switch($node->type){
case 'nodetype1':
return nodetype1_form();
break;
case 'nodetype2':
return nodetype2_form();
break;
.....
}
}
When I created new data after I made those changes you have provided, hook_load is called. It works! I've tested several times(testing with old data created by previous code and testing with new data created after those changes) to make sure if that's the root cause and, I got the same result.I think drupal store form_id or module entry value of node declaration along with data and determine the hook_load call. That's probably the reason why it doesn't think it's a data of this node and thus hook_load isn't invoked.
And Thank you so much for your help.

Weird problem with hook_view drupal

I'm having a weird problem with hook_view. The problem is, hook_view isn't invoked unless hook_load returns invalid value such as empty variable. I don't know what causes this to happen and I'm at my wit's end. I'm very much appreciate your help. For what is worth, I have image attach module installed.
Drupal 6.x
UPDATE
function mymodule_node_info(){
return array(
'nodetype1' => array(
'name' => t('nodetype1'),
'module' => 'mymodule_nodetype1',
'description' => t('....'),
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => TRUE,
'body_label' => t('Body'),
),
'nodetype2' => array(
......
'module' => 'mymodule_nodetype2',
......
),
'nodetype3' => array(
......
'module' => 'mymodule_nodetype3',
......
),
'nodetype4' => array(
......
'module' => 'mymodule_nodetype4',
.......
),
);
}
function mymodule_nodetype1_load($node){
$query = 'SELECT f1,f2,...,f10 FROM {tb1} INNER JOIN {tb2} ON {tb1}.vid = {tb2}.vid WHERE {tb1}.vid = %d';
$result = db_query($query,$node->vid);
return db_fetch_object($result);
}
function mymodule_nodetype1_view($node, $teaser = FALSE, $page = FALSE){
$node = node_prepare($node, $teaser); // get it ready for display
$f1 = check_markup($node->f1);
..............
$f10 = check_markup($node->f10);
// Add theme stuff here
$node->content['mycontent'] = array(
'#value' => theme('defaultskin', $f1,...,$f10),
'#weight' => 1,
);
return $node;
}
function mymodule_theme(){
return array(
'defaultskin' => array(
'template' => 'node-defaultskin',
'arguments' => array(
'f1' => NULL,
......
'f10' => NULL,
),
),
);
}
I found the culprit. Just in case somebody run into same problem I did, here's why - I named one field as "TYPE" and, when I retrieved recordset inside hook_load with drupal_fetch_object, I believe, the resulted object's member name "type" might have caused some naming conflict with drupal core member. As a result, this causes it to not invoke hook_view. After I renamed my field to something different, it works like charm. So, never name field as "Type". You guys might have knew that too but, due to my intention to make code easier to read, I renamed those fields to much simpler ones (f1,...f10). Sorry for the trouble. And thanks everyone for your effort.
cheers
This hook is meant for usage in a node module(so a module that itself creates a new node type), I assume you're using it for nodes defined by Drupal or CKK or another module, if so, use hook_nodeapi() instead with the view argument.
http://api.drupal.org/api/function/hook_nodeapi/6

Resources