Can't see custom attributes set on a user from their Google_Service_Directory_User object - google-admin-sdk

When a custom attribute is set on a user from googles admin page I am unable to see it in their Google_Service_Directory_User object the client has this scope and is able to see the users data but no attributes are shown.
$client->setScopes(
[
Google_Service_Directory::ADMIN_DIRECTORY_USER_READONLY,
Google_Service_Directory::ADMIN_DIRECTORY_GROUP_READONLY,
]
);
I would have expected it to be in the customSchemas but that is null for all the users

When requesting user's informations, you need to set the projection parameter to FULL when using the method users.get (projection parameter is also avaible with method users.list). Default settings to not return custom schemas. You can have more informations here (Google documentation).
You seem to be using PHP (I've never coded in PHP so I may be wrong), so the request should look like this:
$optParams = array(
'userKey' => 'my_customer#example.com',
'projection' => 'full', // or maybe 'FULL' ?
);
$results = $service->users->get($optParams);
If you only want the return some of the schemas, then use :
$optParams = array(
'userKey' => 'my_customer#example.com',
'projection' => 'custom', // or maybe 'CUSTOM' ?,
'customFieldMask' => 'A comma-separated list of schema names'
);
$results = $service->users->get($optParams);

Related

WP_Query meta_query REGEXP

I am pretty much below beginner level for REGEX/REGEXP and have hit a blocking point in a project I am working in, where I am trying to get the ids for posts that match the search criteria , but I want to restrict the search between 2 sub-strings. I am trying to figure out is how to write the REGEXP in the meta_query:
$args = array(
'post_type'=> 'custom',
'order' => 'DESC',
'posts_per_page' => 10,
'paged' => $page,
'meta_query' => array(
array(
'key' => 'key',
'value' => "title*".$search."*_title",
'compare' => 'REGEXP',
)
),
);
And an example of the field in the DB :
a:302:{s:5:"title";s:10:"Test title";s:6:"_title";s:19:"
Unfortunately none of the combinations I tried based on documentation of SQL REGEXP won't return any values and I am trying to understand how I can pull this off and would appreciate any input.
Also would rather stick to WP_Query for now even though an SQL LIKE "%title%{$search}%_title%" works perfectly , so an alternative solution would be how to set the compare to 'LIKE' and parse it '%' since that is not possible out of the box as the % get escaped I believe.

Symfony 3.2 - set environment variables in runtime [duplicate]

In my config.yml I have this:
parameters:
gitek.centro_por_defecto: 1
Now, I want to change this value from my controller using a form, like this:
public function seleccionAction(Request $request)
{
$entity = new Centro();
$form = $this->createForm(new SeleccionType(), $entity);
$centro = $this->container->getParameter('gitek.centro_por_defecto');
if ($this->getRequest()->getMethod() == 'POST') {
$form->bind($this->getRequest());
if ($form->isValid()) {
$miseleccion = $request->request->get('selecciontype');
$this->container->setParameter('gitek.centro_por_defecto', $miseleccion['nombre']);
// return $this->redirect($this->generateUrl('admin_centro'));
}
}
return $this->render('BackendBundle:Centro:seleccion.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
I´m getting Impossible to call set() on a frozen ParameterBag. error all the time.
Any help or clue?
You can't modify Container once it has been compiled, which is done before invoking the controller.
The DIC parameters are intended for configuration purposes - not a replacement for global variables. In addition it seems you want to persist some kind of permanent modification. In that case consider using session if it's a per-user modification or persisting it (e.g. into DB) if it's supposed to be application-wide.
If you need to modify DIC parameters or services, you can do so using a compiler pass. More info on how to write custom compiler passes can be found at:
http://symfony.com/doc/master/cookbook/service_container/compiler_passes.html
You can set $_ENV variables and get that after
putenv("VAR=1");
And to get
getenv("VAR");

Drupal 8: programmatically create node and redirect to it using form api

How do you programmatically add a node from a custom form (forms api) and then redirect to that node after saving it?
Figured out the below answer after looking for half a day.
Hope this is useful to someone else!
'type' is the node machine name
'title' is the title you want to give the new node
you can add more 'field_names' that are used in your node
use Drupal\node\Entity\Node;
use Drupal\Core\Url;
public function submitForm(array &$form, FormStateInterface $form_state) {
$newCompanyNode = Node::create([
'type' => 'company',
'title' => $form_state->getValue('company'),
//'field_name' => $value,
]);
$newCompanyNode->save();
drupal_set_message('Your company has been registered.', 'status');
$url = \Drupal\Core\Url::fromRoute('entity.node.canonical', ['node' => $newCompanyNode->id()]);
return $form_state->setRedirectUrl($url);
}
For more info on how to setup a custom form:
https://www.drupal.org/docs/8/api/form-api/introduction-to-form-api

rails4 Devise omniauth How to modify dynamically one of the strategy options?

I am using Devise+Omniauth , and I defined my own doorkeeper strategy to add a language option
In config/initializers/devise.rb , I set up :
require 'omniauth/strategies/doorkeeper'
config.omniauth :doorkeeper, Rails.application.secrets.doorkeeper_app_id, Rails.application.secrets.doorkeeper_app_secret,
:client_options => {
:site => Rails.application.secrets.doorkeeper_url
},
:authorize_params =>{:lang => I18n.locale}
which initially set lang to :en ( default locale )
this works fine and send the lang options to the remote server for Doorkeeperprocessing
now, how can I change this parameter in my client calling controller ?
I tried to use :
def index
I18n.locale = :fr
Rails.application.config.middleware.use OmniAuth::Builder do
provider :doorkeeper, :setup => lambda{|env| env['omniauth.strategy'].options[:authorize_params][:lang] = env['rack.session'][I18n.locale] }
end
but I got an error :
RuntimeError (can't modify frozen Array):
app/controllers/home_controller.rb:7:in `index'
Is there any better way to do it ? thanks for help
I modified the config/initializers/devise.rb, adding :setup => true
require 'omniauth/strategies/doorkeeper'
config.omniauth :doorkeeper, Rails.application.secrets.doorkeeper_app_id, Rails.application.secrets.doorkeeper_app_secret,
:client_options => {
:site => Rails.application.secrets.doorkeeper_url
},
:authorize_params =>{:lang => I18n.locale},
:setup => true
and I modified my doorkeeper strategy, to include the setup_phase, in which I set the lang option to the current locale.
def setup_phase
request.env['omniauth.strategy'].options[:authorize_params][:lang] = request.params["locale"]
end

Symfony2, Doctrine 2: getResult Object

$posts = $em->find('Application\BlogBundle\Entity\Post',1);
print_r ($posts);
Why I got it?
Barii\BlogBundle\Entity\Post Object ( [id:Barii\BlogBundle\Entity\Post:private] => 1 [title:Application\BlogBundle\Entity\Post:private] => something [body:Application\BlogBundle\Entity\Post:private] => content )
instead of a simple array like this:
array ( [id] => 1,
[title] => "something",
[body] => "content" )
I use it with Symfony 2.
You have a couple options here. As far as I know, you can't find results as arrays from entity repositories by default. Instead, you can do one of two things:
First, you could implement a toArray() method on your entity object (perhaps through a mapped superclass) that simply returns an array of properties.
Second, you could use Doctrine Query Language to pull the information that you need using the getArrayResult() method, perhaps something like this:
$query = $em->createQuery('SELECT p FROM Application\BlogBundle\Entity\Post p WHERE p.id=:pid');
$query->setParameter('tid', $postId);
$result = $query->getArrayResult(); // shortcut for $query->getResult(Query::HYDRATE_ARRAY);
More in-depth documentation on DQL can be found here.